[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/plugins/editors/tinymce/src/Field/ -> TemplateslistField.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Plugin
   5   * @subpackage  Editors.tinymce
   6   *
   7   * @copyright   (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  namespace Joomla\Plugin\Editors\TinyMCE\Field;
  12  
  13  use Joomla\CMS\Form\Field\FolderlistField;
  14  use Joomla\CMS\HTML\HTMLHelper;
  15  use Joomla\CMS\Language\Text;
  16  
  17  // phpcs:disable PSR1.Files.SideEffects
  18  \defined('_JEXEC') or die;
  19  // phpcs:enable PSR1.Files.SideEffects
  20  
  21  /**
  22   * Generates the list of directories available for template snippets.
  23   *
  24   * @since       4.1.0
  25   */
  26  class TemplatesListField extends FolderlistField
  27  {
  28      protected $type = 'templatesList';
  29  
  30      /**
  31       * Method to attach a JForm object to the field.
  32       *
  33       * @param   \SimpleXMLElement  $element  The SimpleXMLElement object representing the `<field>` tag for the form field object.
  34       * @param   mixed              $value    The form field value to validate.
  35       * @param   string             $group    The field name group control value. This acts as an array container for the field.
  36       *                                       For example if the field has name="foo" and the group value is set to "bar" then the
  37       *                                       full field name would end up being "bar[foo]".
  38       *
  39       * @return  boolean  True on success.
  40       *
  41       * @see     \Joomla\CMS\Form\FormField::setup()
  42       * @since   4.1.0
  43       */
  44      public function setup(\SimpleXMLElement $element, $value, $group = null)
  45      {
  46          $return = parent::setup($element, $value, $group);
  47  
  48          // Set some defaults.
  49          $this->recursive   = true;
  50          $this->hideDefault = true;
  51          $this->exclude     = 'system';
  52          $this->hideNone    = true;
  53  
  54          return $return;
  55      }
  56  
  57      /**
  58       * Method to get the directories options.
  59       *
  60       * @return  array  The dirs option objects.
  61       *
  62       * @since   4.1.0
  63       */
  64      public function getOptions()
  65      {
  66          $def         = new \stdClass();
  67          $def->value  = '';
  68          $def->text   = Text::_('JOPTION_DO_NOT_USE');
  69          $options     = [0 => $def];
  70          $directories = [JPATH_ROOT . '/templates', JPATH_ROOT . '/media/templates/site'];
  71  
  72          foreach ($directories as $directory) {
  73              $this->directory = $directory;
  74              $options         = array_merge($options, parent::getOptions());
  75          }
  76  
  77          return $options;
  78      }
  79  
  80      /**
  81       * Method to get the field input markup for the list of directories.
  82       *
  83       * @return  string  The field input markup.
  84       *
  85       * @since   4.1.0
  86       */
  87      protected function getInput()
  88      {
  89          return HTMLHelper::_(
  90              'select.genericlist',
  91              (array) $this->getOptions(),
  92              $this->name,
  93              'class="form-select"',
  94              'value',
  95              'text',
  96              $this->value,
  97              $this->id
  98          );
  99      }
 100  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer