[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/layouts/joomla/form/field/radio/ -> buttons.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  extract($displayData);
  14  
  15  /**
  16   * Layout variables
  17   * -----------------
  18   * @var   string   $autocomplete    Autocomplete attribute for the field.
  19   * @var   boolean  $autofocus       Is autofocus enabled?
  20   * @var   string   $class           Classes for the input.
  21   * @var   string   $description     Description of the field.
  22   * @var   boolean  $disabled        Is this field disabled?
  23   * @var   string   $group           Group the field belongs to. <fields> section in form XML.
  24   * @var   boolean  $hidden          Is this field hidden in the form?
  25   * @var   string   $hint            Placeholder for the field.
  26   * @var   string   $id              DOM id of the field.
  27   * @var   string   $label           Label of the field.
  28   * @var   string   $labelclass      Classes to apply to the label.
  29   * @var   boolean  $multiple        Does this field support multiple values?
  30   * @var   string   $name            Name of the input field.
  31   * @var   string   $onchange        Onchange attribute for the field.
  32   * @var   string   $onclick         Onclick attribute for the field.
  33   * @var   string   $pattern         Pattern (Reg Ex) of value of the form field.
  34   * @var   boolean  $readonly        Is this field read only?
  35   * @var   boolean  $repeat          Allows extensions to duplicate elements.
  36   * @var   boolean  $required        Is this field required?
  37   * @var   integer  $size            Size attribute of the input.
  38   * @var   boolean  $spellcheck      Spellcheck state for the form field.
  39   * @var   string   $validate        Validation rules to apply.
  40   * @var   string   $value           Value attribute of the field.
  41   * @var   array    $options         Options available for this field.
  42   * @var   string   $dataAttribute   Miscellaneous data attributes preprocessed for HTML output
  43   * @var   array    $dataAttributes  Miscellaneous data attributes for eg, data-*.
  44   */
  45  
  46  $alt         = preg_replace('/[^a-zA-Z0-9_\-]/', '_', $name);
  47  $isBtnGroup  = strpos(trim($class), 'btn-group') !== false;
  48  $isBtnYesNo  = strpos(trim($class), 'btn-group-yesno') !== false;
  49  $classToggle = $isBtnGroup ? 'btn-check' : 'form-check-input';
  50  $btnClass    = $isBtnGroup ? 'btn btn-outline-secondary' : 'form-check-label';
  51  $blockStart  = $isBtnGroup ? '' : '<div class="form-check">';
  52  $blockEnd    = $isBtnGroup ? '' : '</div>';
  53  
  54  // Add the attributes of the fieldset in an array
  55  $containerClass = trim($class . ' radio' . ($readonly || $disabled ? ' disabled' : '') . ($readonly ? ' readonly' : ''));
  56  
  57  $attribs = ['id="' . $id . '"'];
  58  
  59  if (!empty($disabled)) {
  60      $attribs[] = 'disabled';
  61  }
  62  
  63  if (!empty($autofocus)) {
  64      $attribs[] = 'autofocus';
  65  }
  66  
  67  if ($readonly || $disabled) {
  68      $attribs[] = 'style="pointer-events: none"';
  69  }
  70  
  71  if ($dataAttribute) {
  72      $attribs[] = $dataAttribute;
  73  }
  74  ?>
  75  <fieldset <?php echo implode(' ', $attribs); ?>>
  76      <legend class="visually-hidden">
  77          <?php echo $label; ?>
  78      </legend>
  79      <div class="<?php echo $containerClass; ?>">
  80          <?php foreach ($options as $i => $option) : ?>
  81              <?php echo $blockStart; ?>
  82                  <?php
  83                  $disabled = !empty($option->disable) ? 'disabled' : '';
  84                  $style    = $disabled ? ' style="pointer-events: none"' : '';
  85  
  86                  // Initialize some option attributes.
  87                  if ($isBtnYesNo) {
  88                      // Set the button classes for the yes/no group
  89                      switch ($option->value) {
  90                          case '0':
  91                              $btnClass = 'btn btn-outline-danger';
  92                              break;
  93                          case '1':
  94                              $btnClass = 'btn btn-outline-success';
  95                              break;
  96                          default:
  97                              $btnClass = 'btn btn-outline-secondary';
  98                              break;
  99                      }
 100                  }
 101  
 102                  $optionClass = !empty($option->class) ? $option->class : $btnClass;
 103                  $optionClass = trim($optionClass . ' ' . $disabled);
 104                  $checked     = ((string) $option->value === $value) ? 'checked="checked"' : '';
 105  
 106                  // Initialize some JavaScript option attributes.
 107                  $onclick    = !empty($option->onclick) ? 'onclick="' . $option->onclick . '"' : '';
 108                  $onchange   = !empty($option->onchange) ? 'onchange="' . $option->onchange . '"' : '';
 109                  $oid        = $id . $i;
 110                  $ovalue     = htmlspecialchars($option->value, ENT_COMPAT, 'UTF-8');
 111                  $attributes = array_filter(array($checked, $disabled, ltrim($style), $onchange, $onclick));
 112                  ?>
 113                  <?php if ($required) : ?>
 114                      <?php $attributes[] = 'required'; ?>
 115                  <?php endif; ?>
 116                  <input class="<?php echo $classToggle; ?>" type="radio" id="<?php echo $oid; ?>" name="<?php echo $name; ?>" value="<?php echo $ovalue; ?>" <?php echo implode(' ', $attributes); ?>>
 117                  <label for="<?php echo $oid; ?>" class="<?php echo trim($optionClass); ?>"<?php echo $style; ?>>
 118                      <?php echo $option->text; ?>
 119                  </label>
 120              <?php echo $blockEnd; ?>
 121          <?php endforeach; ?>
 122      </div>
 123  </fieldset>


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