[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_fields/src/Field/ -> TypeField.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_fields
   6   *
   7   * @copyright   (C) 2016 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  namespace Joomla\Component\Fields\Administrator\Field;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Form\Field\ListField;
  15  use Joomla\CMS\HTML\HTMLHelper;
  16  use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
  17  
  18  // phpcs:disable PSR1.Files.SideEffects
  19  \defined('_JEXEC') or die;
  20  // phpcs:enable PSR1.Files.SideEffects
  21  
  22  /**
  23   * Fields Type
  24   *
  25   * @since  3.7.0
  26   */
  27  class TypeField extends ListField
  28  {
  29      /**
  30       * @var    string
  31       */
  32      public $type = 'Type';
  33  
  34      /**
  35       * Method to attach a JForm object to the field.
  36       *
  37       * @param   \SimpleXMLElement  $element  The SimpleXMLElement object representing the `<field>` tag for the form field object.
  38       * @param   mixed              $value    The form field value to validate.
  39       * @param   string             $group    The field name group control value. This acts as an array container for the field.
  40       *                                       For example if the field has name="foo" and the group value is set to "bar" then the
  41       *                                       full field name would end up being "bar[foo]".
  42       *
  43       * @return  boolean  True on success.
  44       *
  45       * @since   3.7.0
  46       */
  47      public function setup(\SimpleXMLElement $element, $value, $group = null)
  48      {
  49          $return = parent::setup($element, $value, $group);
  50  
  51          $this->onchange = 'Joomla.typeHasChanged(this);';
  52  
  53          return $return;
  54      }
  55  
  56      /**
  57       * Method to get the field options.
  58       *
  59       * @return  array  The field option objects.
  60       *
  61       * @since   3.7.0
  62       */
  63      protected function getOptions()
  64      {
  65          $options = parent::getOptions();
  66  
  67          $fieldTypes = FieldsHelper::getFieldTypes();
  68  
  69          foreach ($fieldTypes as $fieldType) {
  70              $options[] = HTMLHelper::_('select.option', $fieldType['type'], $fieldType['label']);
  71          }
  72  
  73          // Sorting the fields based on the text which is displayed
  74          usort(
  75              $options,
  76              function ($a, $b) {
  77                  return strcmp($a->text, $b->text);
  78              }
  79          );
  80  
  81          // Load scripts
  82          Factory::getApplication()->getDocument()->getWebAssetManager()
  83              ->useScript('com_fields.admin-field-typehaschanged')
  84              ->useScript('webcomponent.core-loader');
  85  
  86          return $options;
  87      }
  88  }


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