[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_categories/src/Field/ -> ComponentsCategoryField.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_categories
   6   *
   7   * @copyright   (C) 2017 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\Categories\Administrator\Field;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Form\Field\ListField;
  15  use Joomla\CMS\Language\Text;
  16  use Joomla\Utilities\ArrayHelper;
  17  
  18  // phpcs:disable PSR1.Files.SideEffects
  19  \defined('_JEXEC') or die;
  20  // phpcs:enable PSR1.Files.SideEffects
  21  
  22  /**
  23   * Components Category field.
  24   *
  25   * @since  1.6
  26   */
  27  class ComponentsCategoryField extends ListField
  28  {
  29      /**
  30       * The form field type.
  31       *
  32       * @var     string
  33       * @since   3.7.0
  34       */
  35      protected $type = 'ComponentsCategory';
  36  
  37      /**
  38       * Method to get a list of options for a list input.
  39       *
  40       * @return  array  An array of JHtml options.
  41       *
  42       * @since   3.7.0
  43       */
  44      protected function getOptions()
  45      {
  46          // Initialise variable.
  47          $db      = $this->getDatabase();
  48          $options = array();
  49  
  50          $query = $db->getQuery(true);
  51          $query->select('DISTINCT ' . $db->quoteName('extension'))
  52              ->from($db->quoteName('#__categories'))
  53              ->where($db->quoteName('extension') . ' != ' . $db->quote('system'));
  54  
  55          $db->setQuery($query);
  56          $categoryTypes = $db->loadColumn();
  57  
  58          foreach ($categoryTypes as $categoryType) {
  59              $option        = new \stdClass();
  60              $option->value = $categoryType;
  61  
  62              // Extract the component name and optional section name
  63              $parts     = explode('.', $categoryType);
  64              $component = $parts[0];
  65              $section   = (\count($parts) > 1) ? $parts[1] : null;
  66  
  67              // Load component language files
  68              $lang = Factory::getLanguage();
  69              $lang->load($component, JPATH_BASE)
  70              || $lang->load($component, JPATH_ADMINISTRATOR . '/components/' . $component);
  71  
  72              // If the component section string exists, let's use it
  73              if ($lang->hasKey($component_section_key = strtoupper($component . ($section ? "_$section" : '')))) {
  74                  $option->text = Text::_($component_section_key);
  75              } else // Else use the component title
  76              {
  77                  $option->text = Text::_(strtoupper($component));
  78              }
  79  
  80              $options[] = $option;
  81          }
  82  
  83          // Sort by name
  84          $options = ArrayHelper::sortObjects($options, 'text', 1, true, true);
  85  
  86          // Merge any additional options in the XML definition.
  87          $options = array_merge(parent::getOptions(), $options);
  88  
  89          return $options;
  90      }
  91  }


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