[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_categories/layouts/joomla/form/field/ -> categoryedit.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_categories
   6   *
   7   * @copyright   (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  defined('_JEXEC') or die;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\HTML\HTMLHelper;
  15  use Joomla\CMS\Language\Text;
  16  
  17  extract($displayData);
  18  
  19  /**
  20   * Layout variables
  21   * -----------------
  22   * @var   string   $autocomplete    Autocomplete attribute for the field.
  23   * @var   boolean  $autofocus       Is autofocus enabled?
  24   * @var   string   $class           Classes for the input.
  25   * @var   string   $description     Description of the field.
  26   * @var   boolean  $disabled        Is this field disabled?
  27   * @var   string   $group           Group the field belongs to. <fields> section in form XML.
  28   * @var   boolean  $hidden          Is this field hidden in the form?
  29   * @var   string   $hint            Placeholder for the field.
  30   * @var   string   $id              DOM id of the field.
  31   * @var   string   $label           Label of the field.
  32   * @var   string   $labelclass      Classes to apply to the label.
  33   * @var   boolean  $multiple        Does this field support multiple values?
  34   * @var   string   $name            Name of the input field.
  35   * @var   string   $onchange        Onchange attribute for the field.
  36   * @var   string   $onclick         Onclick attribute for the field.
  37   * @var   string   $pattern         Pattern (Reg Ex) of value of the form field.
  38   * @var   boolean  $readonly        Is this field read only?
  39   * @var   boolean  $repeat          Allows extensions to duplicate elements.
  40   * @var   boolean  $required        Is this field required?
  41   * @var   integer  $size            Size attribute of the input.
  42   * @var   boolean  $spellcheck      Spellcheck state for the form field.
  43   * @var   string   $validate        Validation rules to apply.
  44   * @var   string   $value           Value attribute of the field.
  45   * @var   array    $checkedOptions  Options that will be set as checked.
  46   * @var   boolean  $hasValue        Has this field a value assigned?
  47   * @var   array    $options         Options available for this field.
  48   * @var   array    $inputType       Options available for this field.
  49   * @var   string   $accept          File types that are accepted.
  50   * @var   string   $customPrefix    Optional prefix for new categories.
  51   */
  52  
  53  $html    = array();
  54  $classes = array();
  55  $attr    = '';
  56  $attr2   = '';
  57  
  58  // Initialize some field attributes.
  59  $attr .= !empty($size) ? ' size="' . $size . '"' : '';
  60  $attr .= $multiple ? ' multiple' : '';
  61  $attr .= $autofocus ? ' autofocus' : '';
  62  $attr .= $onchange ? ' onchange="' . $onchange . '"' : '';
  63  
  64  // To avoid user's confusion, readonly="true" should imply disabled="disabled".
  65  if ($readonly || $disabled) {
  66      $attr .= ' disabled="disabled"';
  67  }
  68  
  69  $attr2 .= !empty($class) ? ' class="' . $class . '"' : '';
  70  
  71  $placeholder = $this->escape(Text::_('JGLOBAL_TYPE_OR_SELECT_CATEGORY'));
  72  
  73  $attr2 .= ' placeholder="' . $placeholder . '" ';
  74  $attr2 .= ' search-placeholder="' . $placeholder . '" ';
  75  
  76  if ($allowCustom) {
  77      $attr2 .= ' allow-custom';
  78  
  79      if ($customPrefix !== '') {
  80          $attr2 .= ' new-item-prefix="' . $customPrefix . '" ';
  81      }
  82  }
  83  
  84  if ($required) {
  85      $attr  .= ' required class="required"';
  86      $attr2 .= ' required';
  87  }
  88  
  89  // Create a read-only list (no name) with hidden input(s) to store the value(s).
  90  if ($readonly) {
  91      $html[] = HTMLHelper::_('select.genericlist', $options, '', trim($attr), 'value', 'text', $value, $id);
  92  
  93      // E.g. form field type tag sends $this->value as array
  94      if ($multiple && is_array($value)) {
  95          if (!count($value)) {
  96              $value[] = '';
  97          }
  98  
  99          foreach ($value as $val) {
 100              $html[] = '<input type="hidden" name="' . $name . '" value="' . htmlspecialchars($val, ENT_COMPAT, 'UTF-8') . '">';
 101          }
 102      } else {
 103          $html[] = '<input type="hidden" name="' . $name . '" value="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '">';
 104      }
 105  } else {
 106      // Create a regular list.
 107      if (count($options) === 0) {
 108          // All Categories have been deleted, so we need a new category (This will create on save if selected).
 109          $options[0]            = new \stdClass();
 110          $options[0]->value     = 'Uncategorised';
 111          $options[0]->text      = 'Uncategorised';
 112          $options[0]->level     = '1';
 113          $options[0]->published = '1';
 114          $options[0]->lft       = '1';
 115      }
 116  
 117      $html[] = HTMLHelper::_('select.genericlist', $options, $name, trim($attr), 'value', 'text', $value, $id);
 118  }
 119  
 120  if ($refreshPage === true) {
 121      $attr2 .= ' data-refresh-catid="' . $refreshCatId . '" data-refresh-section="' . $refreshSection . '"';
 122      $attr2 .= ' onchange="Joomla.categoryHasChanged(this)"';
 123  
 124      Factory::getDocument()->getWebAssetManager()
 125          ->registerAndUseScript('field.category-change', 'layouts/joomla/form/field/category-change.min.js', [], ['defer' => true], ['core'])
 126          ->useScript('webcomponent.core-loader');
 127  
 128      // Pass the element id to the javascript
 129      Factory::getDocument()->addScriptOptions('category-change', $id);
 130  } else {
 131      $attr2 .= $onchange ? ' onchange="' . $onchange . '"' : '';
 132  }
 133  
 134  Text::script('JGLOBAL_SELECT_NO_RESULTS_MATCH');
 135  Text::script('JGLOBAL_SELECT_PRESS_TO_SELECT');
 136  
 137  Factory::getDocument()->getWebAssetManager()
 138      ->usePreset('choicesjs')
 139      ->useScript('webcomponent.field-fancy-select');
 140  ?>
 141  
 142  <joomla-field-fancy-select <?php echo $attr2; ?>><?php echo implode($html); ?></joomla-field-fancy-select>


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