[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/api/components/com_plugins/src/Controller/ -> PluginsController.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.API
   5   * @subpackage  com_plugins
   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\Plugins\Api\Controller;
  12  
  13  use Joomla\CMS\Filter\InputFilter;
  14  use Joomla\CMS\Language\Text;
  15  use Joomla\CMS\MVC\Controller\ApiController;
  16  use Joomla\CMS\MVC\Controller\Exception;
  17  use Joomla\CMS\Router\Exception\RouteNotFoundException;
  18  use Joomla\String\Inflector;
  19  use Tobscure\JsonApi\Exception\InvalidParameterException;
  20  
  21  // phpcs:disable PSR1.Files.SideEffects
  22  \defined('_JEXEC') or die;
  23  // phpcs:enable PSR1.Files.SideEffects
  24  
  25  /**
  26   * The plugins controller
  27   *
  28   * @since  4.0.0
  29   */
  30  class PluginsController extends ApiController
  31  {
  32      /**
  33       * The content type of the item.
  34       *
  35       * @var    string
  36       * @since  4.0.0
  37       */
  38      protected $contentType = 'plugins';
  39  
  40      /**
  41       * The default view for the display method.
  42       *
  43       * @var    string
  44       *
  45       * @since  3.0
  46       */
  47      protected $default_view = 'plugins';
  48  
  49      /**
  50       * Method to edit an existing record.
  51       *
  52       * @return  static  A \JControllerLegacy object to support chaining.
  53       *
  54       * @since   4.0.0
  55       */
  56      public function edit()
  57      {
  58          $recordId = $this->input->getInt('id');
  59  
  60          if (!$recordId) {
  61              throw new Exception\ResourceNotFound(Text::_('JLIB_APPLICATION_ERROR_RECORD'), 404);
  62          }
  63  
  64          $data = json_decode($this->input->json->getRaw(), true);
  65  
  66          foreach ($data as $key => $value) {
  67              if (!\in_array($key, ['enabled', 'access', 'ordering'])) {
  68                  throw new InvalidParameterException("Invalid parameter {$key}.", 400);
  69              }
  70          }
  71  
  72          /** @var \Joomla\Component\Plugins\Administrator\Model\PluginModel $model */
  73          $model = $this->getModel(Inflector::singularize($this->contentType), '', ['ignore_request' => true]);
  74  
  75          if (!$model) {
  76              throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_MODEL_CREATE'));
  77          }
  78  
  79          $item = $model->getItem($recordId);
  80  
  81          if (!isset($item->extension_id)) {
  82              throw new RouteNotFoundException('Item does not exist');
  83          }
  84  
  85          $data['folder']  = $item->folder;
  86          $data['element'] = $item->element;
  87  
  88          $this->input->set('data', $data);
  89  
  90          return parent::edit();
  91      }
  92  
  93      /**
  94       * Plugin list view with filtering of data
  95       *
  96       * @return  static  A BaseController object to support chaining.
  97       *
  98       * @since   4.0.0
  99       */
 100      public function displayList()
 101      {
 102          $apiFilterInfo = $this->input->get('filter', [], 'array');
 103          $filter        = InputFilter::getInstance();
 104  
 105          if (\array_key_exists('element', $apiFilterInfo)) {
 106              $this->modelState->set('filter.element', $filter->clean($apiFilterInfo['element'], 'STRING'));
 107          }
 108  
 109          if (\array_key_exists('status', $apiFilterInfo)) {
 110              $this->modelState->set('filter.enabled', $filter->clean($apiFilterInfo['status'], 'INT'));
 111          }
 112  
 113          if (\array_key_exists('search', $apiFilterInfo)) {
 114              $this->modelState->set('filter.search', $filter->clean($apiFilterInfo['search'], 'STRING'));
 115          }
 116  
 117          if (\array_key_exists('type', $apiFilterInfo)) {
 118              $this->modelState->set('filter.folder', $filter->clean($apiFilterInfo['type'], 'STRING'));
 119          }
 120  
 121          return parent::displayList();
 122      }
 123  }


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