[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/api/components/com_modules/src/Controller/ -> ModulesController.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.API
   5   * @subpackage  com_modules
   6   *
   7   * @copyright   (C) 2019 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\Modules\Api\Controller;
  12  
  13  use Joomla\CMS\Language\Text;
  14  use Joomla\CMS\MVC\Controller\ApiController;
  15  use Joomla\Component\Modules\Administrator\Model\SelectModel;
  16  use Joomla\Component\Modules\Api\View\Modules\JsonapiView;
  17  
  18  // phpcs:disable PSR1.Files.SideEffects
  19  \defined('_JEXEC') or die;
  20  // phpcs:enable PSR1.Files.SideEffects
  21  
  22  /**
  23   * The modules controller
  24   *
  25   * @since  4.0.0
  26   */
  27  class ModulesController extends ApiController
  28  {
  29      /**
  30       * The content type of the item.
  31       *
  32       * @var    string
  33       * @since  4.0.0
  34       */
  35      protected $contentType = 'modules';
  36  
  37      /**
  38       * The default view for the display method.
  39       *
  40       * @var    string
  41       * @since  3.0
  42       */
  43      protected $default_view = 'modules';
  44  
  45      /**
  46       * Basic display of an item view
  47       *
  48       * @param   integer  $id  The primary key to display. Leave empty if you want to retrieve data from the request
  49       *
  50       * @return  static  A \JControllerLegacy object to support chaining.
  51       *
  52       * @since   4.0.0
  53       */
  54      public function displayItem($id = null)
  55      {
  56          $this->modelState->set('filter.client_id', $this->getClientIdFromInput());
  57  
  58          return parent::displayItem($id);
  59      }
  60  
  61      /**
  62       * Basic display of a list view
  63       *
  64       * @return  static  A \JControllerLegacy object to support chaining.
  65       *
  66       * @since   4.0.0
  67       */
  68      public function displayList()
  69      {
  70          $this->modelState->set('filter.client_id', $this->getClientIdFromInput());
  71  
  72          return parent::displayList();
  73      }
  74  
  75      /**
  76       * Return module items types
  77       *
  78       * @return  static  A \JControllerLegacy object to support chaining.
  79       *
  80       * @since   4.0.0
  81       */
  82      public function getTypes()
  83      {
  84          $viewType   = $this->app->getDocument()->getType();
  85          $viewName   = $this->input->get('view', $this->default_view);
  86          $viewLayout = $this->input->get('layout', 'default', 'string');
  87  
  88          try {
  89              /** @var JsonapiView $view */
  90              $view = $this->getView(
  91                  $viewName,
  92                  $viewType,
  93                  '',
  94                  ['base_path' => $this->basePath, 'layout' => $viewLayout, 'contentType' => $this->contentType]
  95              );
  96          } catch (\Exception $e) {
  97              throw new \RuntimeException($e->getMessage());
  98          }
  99  
 100          /** @var SelectModel $model */
 101          $model = $this->getModel('select', '', ['ignore_request' => true]);
 102  
 103          if (!$model) {
 104              throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_MODEL_CREATE'));
 105          }
 106  
 107          $model->setState('client_id', $this->getClientIdFromInput());
 108  
 109          $view->setModel($model, true);
 110  
 111          $view->document = $this->app->getDocument();
 112  
 113          $view->displayListTypes();
 114  
 115          return $this;
 116      }
 117  
 118      /**
 119       * Get client id from input
 120       *
 121       * @return string
 122       *
 123       * @since 4.0.0
 124       */
 125      private function getClientIdFromInput()
 126      {
 127          return $this->input->exists('client_id') ?
 128              $this->input->get('client_id') : $this->input->post->get('client_id');
 129      }
 130  }


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