[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Form/Field/ -> TimeField.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\Form\Field;
  11  
  12  use Joomla\CMS\Form\FormField;
  13  
  14  // phpcs:disable PSR1.Files.SideEffects
  15  \defined('JPATH_PLATFORM') or die;
  16  // phpcs:enable PSR1.Files.SideEffects
  17  
  18  /**
  19   * Form Field class for the Joomla Platform.
  20   * Provides a select list of integers with specified first, last and step values.
  21   *
  22   * @since  4.0.0
  23   */
  24  class TimeField extends FormField
  25  {
  26      /**
  27       * The form field type.
  28       *
  29       * @var    string
  30       * @since  4.0.0
  31       */
  32      protected $type = 'Time';
  33  
  34      /**
  35       * The allowable minimal value of the field.
  36       *
  37       * @var    integer
  38       * @since  4.0.0
  39       */
  40      protected $min;
  41  
  42      /**
  43       * The allowable maximal value of the field.
  44       *
  45       * @var    integer
  46       * @since  4.0.0
  47       */
  48      protected $max;
  49  
  50      /**
  51       * Steps between different values
  52       *
  53       * @var    integer
  54       * @since  4.0.0
  55       */
  56      protected $step;
  57  
  58      /**
  59       * Name of the layout being used to render the field
  60       *
  61       * @var    string
  62       * @since  4.0.0
  63       */
  64      protected $layout = 'joomla.form.field.time';
  65  
  66      /**
  67       * Method to set certain otherwise inaccessible properties of the form field object.
  68       *
  69       * @param   string  $name   The property name for which to set the value.
  70       * @param   mixed   $value  The value of the property.
  71       *
  72       * @return  void
  73       *
  74       * @since   4.0.0
  75       */
  76      public function __set($name, $value)
  77      {
  78          switch ($name) {
  79              case 'min':
  80                  $this->min = (string) $value;
  81                  break;
  82  
  83              case 'max':
  84                  $this->max = (string) $value;
  85                  break;
  86  
  87              case 'step':
  88                  $this->step = (string) $value;
  89                  break;
  90  
  91              default:
  92                  parent::__set($name, $value);
  93          }
  94      }
  95  
  96      /**
  97       * Method to attach a Form object to the field.
  98       *
  99       * @param   \SimpleXMLElement  $element  The SimpleXMLElement object representing the `<field>` tag for the form field object.
 100       * @param   mixed              $value    The form field value to validate.
 101       * @param   string             $group    The field name group control value. This acts as an array container for the field.
 102       *                                       For example if the field has name="foo" and the group value is set to "bar" then the
 103       *                                       full field name would end up being "bar[foo]".
 104       *
 105       * @see     FormField::setup()
 106       * @return  boolean  True on success.
 107       *
 108       * @since   4.0.0
 109       */
 110      public function setup(\SimpleXMLElement $element, $value, $group = null)
 111      {
 112          $return = parent::setup($element, $value, $group);
 113  
 114          if ($return) {
 115              // It is better not to force any default limits if none is specified
 116              $this->max  = isset($this->element['max']) ? (string) $this->element['max'] : null;
 117              $this->min  = isset($this->element['min']) ? (string) $this->element['min'] : null;
 118              $this->step = isset($this->element['step']) ? (float) $this->element['step'] : null;
 119          }
 120  
 121          return $return;
 122      }
 123  
 124      /**
 125       * Method to get certain otherwise inaccessible properties from the form field object.
 126       *
 127       * @param   string  $name  The property name for which to get the value.
 128       *
 129       * @return  mixed  The property value or null.
 130       *
 131       * @since   4.0.0
 132       */
 133      public function __get($name)
 134      {
 135          switch ($name) {
 136              case 'min':
 137              case 'max':
 138              case 'step':
 139                  return $this->$name;
 140          }
 141  
 142          return parent::__get($name);
 143      }
 144  
 145      /**
 146       * Method to get the field input markup.
 147       *
 148       * @return  string  The field input markup.
 149       *
 150       * @since   4.0.0
 151       */
 152      protected function getInput()
 153      {
 154          return $this->getRenderer($this->layout)->render($this->getLayoutData());
 155      }
 156  
 157      /**
 158       * Method to get the data to be passed to the layout for rendering.
 159       *
 160       * @return  array
 161       *
 162       * @since 4.0.0
 163       */
 164      protected function getLayoutData()
 165      {
 166          $data = parent::getLayoutData();
 167  
 168          $extraData = [
 169              'min'  => $this->min,
 170              'max'  => $this->max,
 171              'step' => $this->step,
 172          ];
 173  
 174          return array_merge($data, $extraData);
 175      }
 176  }


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