[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_menus/src/Service/HTML/ -> Menus.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_menus
   6   *
   7   * @copyright   (C) 2011 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\Menus\Administrator\Service\HTML;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Language\LanguageHelper;
  15  use Joomla\CMS\Language\Text;
  16  use Joomla\CMS\Layout\LayoutHelper;
  17  use Joomla\CMS\Router\Route;
  18  use Joomla\Component\Menus\Administrator\Helper\MenusHelper;
  19  use Joomla\Database\ParameterType;
  20  use Joomla\Registry\Registry;
  21  
  22  // phpcs:disable PSR1.Files.SideEffects
  23  \defined('_JEXEC') or die;
  24  // phpcs:enable PSR1.Files.SideEffects
  25  
  26  /**
  27   * Menus HTML helper class.
  28   *
  29   * @package     Joomla.Administrator
  30   * @subpackage  com_menus
  31   * @since       1.7
  32   */
  33  class Menus
  34  {
  35      /**
  36       * Generate the markup to display the item associations
  37       *
  38       * @param   int  $itemid  The menu item id
  39       *
  40       * @return  string
  41       *
  42       * @since   3.0
  43       *
  44       * @throws \Exception If there is an error on the query
  45       */
  46      public function association($itemid)
  47      {
  48          // Defaults
  49          $html = '';
  50  
  51          // Get the associations
  52          if ($associations = MenusHelper::getAssociations($itemid)) {
  53              // Get the associated menu items
  54              $db = Factory::getDbo();
  55              $query = $db->getQuery(true)
  56                  ->select(
  57                      [
  58                          $db->quoteName('m.id'),
  59                          $db->quoteName('m.title'),
  60                          $db->quoteName('l.sef', 'lang_sef'),
  61                          $db->quoteName('l.lang_code'),
  62                          $db->quoteName('mt.title', 'menu_title'),
  63                          $db->quoteName('l.image'),
  64                          $db->quoteName('l.title', 'language_title'),
  65                      ]
  66                  )
  67                  ->from($db->quoteName('#__menu', 'm'))
  68                  ->join('LEFT', $db->quoteName('#__menu_types', 'mt'), $db->quoteName('mt.menutype') . ' = ' . $db->quoteName('m.menutype'))
  69                  ->join('LEFT', $db->quoteName('#__languages', 'l'), $db->quoteName('m.language') . ' = ' . $db->quoteName('l.lang_code'))
  70                  ->whereIn($db->quoteName('m.id'), array_values($associations))
  71                  ->where($db->quoteName('m.id') . ' != :itemid')
  72                  ->bind(':itemid', $itemid, ParameterType::INTEGER);
  73              $db->setQuery($query);
  74  
  75              try {
  76                  $items = $db->loadObjectList('id');
  77              } catch (\RuntimeException $e) {
  78                  throw new \Exception($e->getMessage(), 500);
  79              }
  80  
  81              // Construct html
  82              if ($items) {
  83                  $languages = LanguageHelper::getContentLanguages(array(0, 1));
  84                  $content_languages = array_column($languages, 'lang_code');
  85  
  86                  foreach ($items as &$item) {
  87                      if (in_array($item->lang_code, $content_languages)) {
  88                          $text    = $item->lang_code;
  89                          $url     = Route::_('index.php?option=com_menus&task=item.edit&id=' . (int) $item->id);
  90                          $tooltip = '<strong>' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '</strong><br>'
  91                              . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '<br>' . Text::sprintf('COM_MENUS_MENU_SPRINTF', $item->menu_title);
  92                          $classes = 'badge bg-secondary';
  93  
  94                          $item->link = '<a href="' . $url . '" class="' . $classes . '">' . $text . '</a>'
  95                              . '<div role="tooltip" id="tip-' . (int) $itemid . '-' . (int) $item->id . '">' . $tooltip . '</div>';
  96                      } else {
  97                          // Display warning if Content Language is trashed or deleted
  98                          Factory::getApplication()->enqueueMessage(Text::sprintf('JGLOBAL_ASSOCIATIONS_CONTENTLANGUAGE_WARNING', $item->lang_code), 'warning');
  99                      }
 100                  }
 101              }
 102  
 103              $html = LayoutHelper::render('joomla.content.associations', $items);
 104          }
 105  
 106          return $html;
 107      }
 108  
 109      /**
 110       * Returns a visibility state on a grid
 111       *
 112       * @param   integer  $params  Params of item.
 113       *
 114       * @return  string  The Html code
 115       *
 116       * @since   3.7.0
 117       */
 118      public function visibility($params)
 119      {
 120          $registry = new Registry();
 121  
 122          try {
 123              $registry->loadString($params);
 124          } catch (\Exception $e) {
 125              // Invalid JSON
 126          }
 127  
 128          $show_menu = $registry->get('menu_show');
 129  
 130          return ($show_menu === 0) ? '<span class="badge bg-secondary">' . Text::_('COM_MENUS_LABEL_HIDDEN') . '</span>' : '';
 131      }
 132  }


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