[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_menus/src/Controller/ -> AjaxController.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_menus
   6   *
   7   * @copyright   (C) 2005 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\Controller;
  12  
  13  use Joomla\CMS\Language\Associations;
  14  use Joomla\CMS\Language\LanguageHelper;
  15  use Joomla\CMS\Language\Text;
  16  use Joomla\CMS\MVC\Controller\BaseController;
  17  use Joomla\CMS\Response\JsonResponse;
  18  use Joomla\CMS\Session\Session;
  19  use Joomla\CMS\Table\Table;
  20  
  21  // phpcs:disable PSR1.Files.SideEffects
  22  \defined('_JEXEC') or die;
  23  // phpcs:enable PSR1.Files.SideEffects
  24  
  25  /**
  26   * The menu controller for ajax requests
  27   *
  28   * @since  3.9.0
  29   */
  30  class AjaxController extends BaseController
  31  {
  32      /**
  33       * Method to fetch associations of a menu item
  34       *
  35       * The method assumes that the following http parameters are passed in an Ajax Get request:
  36       * token: the form token
  37       * assocId: the id of the menu item whose associations are to be returned
  38       * excludeLang: the association for this language is to be excluded
  39       *
  40       * @return  null
  41       *
  42       * @since  3.9.0
  43       */
  44      public function fetchAssociations()
  45      {
  46          if (!Session::checkToken('get')) {
  47              echo new JsonResponse(null, Text::_('JINVALID_TOKEN'), true);
  48          } else {
  49              $assocId   = $this->input->getInt('assocId', 0);
  50  
  51              if ($assocId == 0) {
  52                  echo new JsonResponse(null, Text::sprintf('JLIB_FORM_VALIDATE_FIELD_INVALID', 'assocId'), true);
  53  
  54                  return;
  55              }
  56  
  57              $excludeLang = $this->input->get('excludeLang', '', 'STRING');
  58  
  59              $associations = Associations::getAssociations('com_menus', '#__menu', 'com_menus.item', (int) $assocId, 'id', '', '');
  60  
  61              unset($associations[$excludeLang]);
  62  
  63              // Add the title to each of the associated records
  64              Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_menus/tables');
  65              $menuTable = Table::getInstance('Menu', 'JTable', array());
  66  
  67              foreach ($associations as $lang => $association) {
  68                  $menuTable->load($association->id);
  69                  $associations[$lang]->title = $menuTable->title;
  70              }
  71  
  72              $countContentLanguages = count(LanguageHelper::getContentLanguages(array(0, 1), false));
  73  
  74              if (count($associations) == 0) {
  75                  $message = Text::_('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_NONE');
  76              } elseif ($countContentLanguages > count($associations) + 2) {
  77                  $tags    = implode(', ', array_keys($associations));
  78                  $message = Text::sprintf('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_SOME', $tags);
  79              } else {
  80                  $message = Text::_('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_ALL');
  81              }
  82  
  83              echo new JsonResponse($associations, $message);
  84          }
  85      }
  86  }


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