[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2016 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\Factory;
  13  use Joomla\CMS\Filesystem\Path;
  14  use Joomla\CMS\Language\Text;
  15  
  16  // phpcs:disable PSR1.Files.SideEffects
  17  \defined('JPATH_PLATFORM') or die;
  18  // phpcs:enable PSR1.Files.SideEffects
  19  
  20  /**
  21   * Form Field class for the Joomla Framework.
  22   *
  23   * @since  2.5.0
  24   */
  25  class AliastagField extends ListField
  26  {
  27      /**
  28       * The field type.
  29       *
  30       * @var    string
  31       * @since  3.6
  32       */
  33      protected $type = 'Aliastag';
  34  
  35      /**
  36       * Method to get a list of options for a list input.
  37       *
  38       * @return  array  An array of JHtml options.
  39       *
  40       * @since   3.6
  41       */
  42      protected function getOptions()
  43      {
  44          // Get list of tag type alias
  45          $db    = $this->getDatabase();
  46          $query = $db->getQuery(true)
  47              ->select(
  48                  [
  49                      'DISTINCT ' . $db->quoteName('type_alias', 'value'),
  50                      $db->quoteName('type_alias', 'text'),
  51                  ]
  52              )
  53              ->from($db->quoteName('#__contentitem_tag_map'));
  54          $db->setQuery($query);
  55  
  56          $options = $db->loadObjectList();
  57  
  58          $lang = Factory::getLanguage();
  59  
  60          foreach ($options as $i => $item) {
  61              $parts     = explode('.', $item->value);
  62              $extension = $parts[0];
  63              $lang->load($extension . '.sys', JPATH_ADMINISTRATOR)
  64              || $lang->load($extension, Path::clean(JPATH_ADMINISTRATOR . '/components/' . $extension));
  65              $options[$i]->text = Text::_(strtoupper($extension) . '_TAGS_' . strtoupper($parts[1]));
  66          }
  67  
  68          // Merge any additional options in the XML definition.
  69          $options = array_merge(parent::getOptions(), $options);
  70  
  71          // Sort by language value
  72          usort(
  73              $options,
  74              function ($a, $b) {
  75                  return strcmp($a->text, $b->text);
  76              }
  77          );
  78  
  79          return $options;
  80      }
  81  }


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