[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Site
   5   * @subpackage  Layout
   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\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    $options         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 the 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 .= $onchange ? ' onchange="' . $onchange . '"' : '';
  58  $attr .= !empty($description) ? ' aria-describedby="' . ($id ?: $name) . '-desc"' : '';
  59  $attr .= $dataAttribute;
  60  
  61  // To avoid user's confusion, readonly="readonly" should imply disabled="disabled".
  62  if ($readonly || $disabled) {
  63      $attr .= ' disabled="disabled"';
  64  }
  65  
  66  // Create a read-only list (no name) with hidden input(s) to store the value(s).
  67  if ($readonly) {
  68      $html[] = HTMLHelper::_('select.genericlist', $options, '', trim($attr), 'value', 'text', $value, $id);
  69  
  70      // E.g. form field type tag sends $this->value as array
  71      if ($multiple && is_array($value)) {
  72          if (!count($value)) {
  73              $value[] = '';
  74          }
  75  
  76          foreach ($value as $val) {
  77              $html[] = '<input type="hidden" name="' . $name . '" value="' . htmlspecialchars($val, ENT_COMPAT, 'UTF-8') . '">';
  78          }
  79      } else {
  80          $html[] = '<input type="hidden" name="' . $name . '" value="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '">';
  81      }
  82  } else // Create a regular list passing the arguments in an array.
  83  {
  84      $listoptions = array();
  85      $listoptions['option.key'] = 'value';
  86      $listoptions['option.text'] = 'text';
  87      $listoptions['list.select'] = $value;
  88      $listoptions['id'] = $id;
  89      $listoptions['list.translate'] = false;
  90      $listoptions['option.attr'] = 'optionattr';
  91      $listoptions['list.attr'] = trim($attr);
  92      $html[] = HTMLHelper::_('select.genericlist', $options, $name, $listoptions);
  93  }
  94  
  95  echo implode($html);


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