[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_fields/src/Field/ -> FieldgroupsField.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\Utilities\ArrayHelper;
  16  
  17  // phpcs:disable PSR1.Files.SideEffects
  18  \defined('_JEXEC') or die;
  19  // phpcs:enable PSR1.Files.SideEffects
  20  
  21  /**
  22   * Fields Groups
  23   *
  24   * @since  3.7.0
  25   */
  26  class FieldgroupsField extends ListField
  27  {
  28      /**
  29       * @var    string
  30       */
  31      public $type = 'Fieldgroups';
  32  
  33      /**
  34       * Method to get the field options.
  35       *
  36       * @return  array  The field option objects.
  37       *
  38       * @since   3.7.0
  39       */
  40      protected function getOptions()
  41      {
  42          $context = (string) $this->element['context'];
  43          $states    = $this->element['state'] ?: '0,1';
  44          $states    = ArrayHelper::toInteger(explode(',', $states));
  45  
  46          $user       = Factory::getUser();
  47          $viewlevels = ArrayHelper::toInteger($user->getAuthorisedViewLevels());
  48  
  49          $db    = $this->getDatabase();
  50          $query = $db->getQuery(true);
  51          $query->select(
  52              [
  53                  $db->quoteName('title', 'text'),
  54                  $db->quoteName('id', 'value'),
  55                  $db->quoteName('state'),
  56              ]
  57          );
  58          $query->from($db->quoteName('#__fields_groups'));
  59          $query->whereIn($db->quoteName('state'), $states);
  60          $query->where($db->quoteName('context') . ' = :context');
  61          $query->whereIn($db->quoteName('access'), $viewlevels);
  62          $query->order('ordering asc, id asc');
  63          $query->bind(':context', $context);
  64  
  65          $db->setQuery($query);
  66          $options = $db->loadObjectList();
  67  
  68          foreach ($options as $option) {
  69              if ($option->state == 0) {
  70                  $option->text = '[' . $option->text . ']';
  71              }
  72  
  73              if ($option->state == 2) {
  74                  $option->text = '{' . $option->text . '}';
  75              }
  76          }
  77  
  78          return array_merge(parent::getOptions(), $options);
  79      }
  80  }


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