[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/layouts/joomla/form/field/ -> groupedlist.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Site
   5   * @subpackage  Layout
   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  defined('_JEXEC') or die;
  12  
  13  use Joomla\CMS\HTML\HTMLHelper;
  14  
  15  extract($displayData);
  16  
  17  /**
  18   * Layout variables
  19   * -----------------
  20   * @var   string   $autocomplete    Autocomplete attribute for the field.
  21   * @var   boolean  $autofocus       Is autofocus enabled?
  22   * @var   string   $class           Classes for the input.
  23   * @var   string   $description     Description of the field.
  24   * @var   boolean  $disabled        Is this field disabled?
  25   * @var   string   $group           Group the field belongs to. <fields> section in form XML.
  26   * @var   boolean  $hidden          Is this field hidden in the form?
  27   * @var   string   $hint            Placeholder for the field.
  28   * @var   string   $id              DOM id of the field.
  29   * @var   string   $label           Label of the field.
  30   * @var   string   $labelclass      Classes to apply to the label.
  31   * @var   boolean  $multiple        Does this field support multiple values?
  32   * @var   string   $name            Name of the input field.
  33   * @var   string   $onchange        Onchange attribute for the field.
  34   * @var   string   $onclick         Onclick attribute for the field.
  35   * @var   string   $pattern         Pattern (Reg Ex) of value of the form field.
  36   * @var   boolean  $readonly        Is this field read only?
  37   * @var   boolean  $repeat          Allows extensions to duplicate elements.
  38   * @var   boolean  $required        Is this field required?
  39   * @var   integer  $size            Size attribute of the input.
  40   * @var   boolean  $spellcheck      Spellcheck state for the form field.
  41   * @var   string   $validate        Validation rules to apply.
  42   * @var   string   $value           Value attribute of the field.
  43   * @var   array    $groups          Groups of options available for this field.
  44   * @var   string   $dataAttribute   Miscellaneous data attributes preprocessed for HTML output
  45   * @var   array    $dataAttributes  Miscellaneous data attribute for eg, data-*
  46   */
  47  
  48  $html = array();
  49  $attr = '';
  50  
  51  // Initialize some field attributes.
  52  $attr .= !empty($class) ? ' class="form-select ' . $class . '"' : ' class="form-select"';
  53  $attr .= !empty($size) ? ' size="' . $size . '"' : '';
  54  $attr .= $multiple ? ' multiple' : '';
  55  $attr .= $required ? ' required' : '';
  56  $attr .= $autofocus ? ' autofocus' : '';
  57  $attr .= $dataAttribute;
  58  
  59  // To avoid user's confusion, readonly="true" should imply disabled="true".
  60  if ($readonly || $disabled) {
  61      $attr .= ' disabled="disabled"';
  62  }
  63  
  64  // Initialize JavaScript field attributes.
  65  $attr .= !empty($onchange) ? ' onchange="' . $onchange . '"' : '';
  66  
  67  // Create a read-only list (no name) with a hidden input to store the value.
  68  if ($readonly) {
  69      $html[] = HTMLHelper::_(
  70          'select.groupedlist',
  71          $groups,
  72          null,
  73          array(
  74              'list.attr' => $attr, 'id' => $id, 'list.select' => $value, 'group.items' => null, 'option.key.toHtml' => false,
  75              'option.text.toHtml' => false,
  76          )
  77      );
  78  
  79      // E.g. form field type tag sends $this->value as array
  80      if ($multiple && \is_array($value)) {
  81          if (!\count($value)) {
  82              $value[] = '';
  83          }
  84  
  85          foreach ($value as $val) {
  86              $html[] = '<input type="hidden" name="' . $name . '" value="' . htmlspecialchars($val, ENT_COMPAT, 'UTF-8') . '">';
  87          }
  88      } else {
  89          $html[] = '<input type="hidden" name="' . $name . '" value="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '">';
  90      }
  91  } else {
  92      // Create a regular list.
  93      $html[] = HTMLHelper::_(
  94          'select.groupedlist',
  95          $groups,
  96          $name,
  97          array(
  98              'list.attr' => $attr, 'id' => $id, 'list.select' => $value, 'group.items' => null, 'option.key.toHtml' => false,
  99              'option.text.toHtml' => false,
 100          )
 101      );
 102  }
 103  
 104  echo implode($html);


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