SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Helpers/LinkSpecPage.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. namespace Sprout\Helpers;
  15.  
  16.  
  17. use Sprout\Helpers\Form;
  18.  
  19.  
  20. class LinkSpecPage extends LinkSpec
  21. {
  22.  
  23. /**
  24.   * Get the URL for a given link
  25.   **/
  26. public function getUrl($specdata)
  27. {
  28. $root = Navigation::getRootNode();
  29. if (! $root) return null;
  30.  
  31. $node = $root->findNodeValue('id', $specdata);
  32. if (! $node) return null;
  33.  
  34. return $node->getFriendlyUrlNoprefix();
  35. }
  36.  
  37.  
  38. /**
  39.   * Get any extra html attributes to use for a given link
  40.   * @return array
  41.   **/
  42. public function getAttrs($specdata)
  43. {
  44. return array();
  45. }
  46.  
  47.  
  48. /**
  49.   * Get the HTML to use for editing a given linkspec
  50.   *
  51.   * The HTML should create a HTML field with the name $field_name
  52.   * If there is a spec currently being edited, the specdata will
  53.   * be provided in $curr_specdata
  54.   **/
  55. public function getEditForm($field_name, $curr_specdata)
  56. {
  57. Form::setData([$field_name => $curr_specdata]);
  58. Form::nextFieldDetails('Page', true);
  59. return Form::pageDropdown($field_name);
  60. }
  61.  
  62.  
  63. /**
  64.   * Validate the submission, for instances where certain constraints apply
  65.   **/
  66. public function isValid($specdata)
  67. {
  68. return true;
  69. }
  70.  
  71. }
  72.