CoreFiles by mySites.guru
JsonapiView.php137 lines, 3,007 bytes, from Joomla_4.2.1-rc2-Release_Candidate-Full_Package.zip
Raw History Compare with 4.2.1-rc1
md5
e2d065b8fd23b9a4eeef975c1ecbc1b8
sha1
f88fab60186ebe3eaa0b53bfe3b82774fa7ba04f
sha256
9d1179ca27dce5878b996335815e28d9cb72403790ae282ed60b0ecaee5537e7
<?php

/**
 * @package     Joomla.API
 * @subpackage  com_modules
 *
 * @copyright   (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Component\Modules\Api\View\Modules;

use Joomla\CMS\MVC\View\JsonApiView as BaseApiView;
use Joomla\CMS\Router\Exception\RouteNotFoundException;
use Joomla\Component\Modules\Administrator\Model\SelectModel;

/**
 * The modules view
 *
 * @since  4.0.0
 */
class JsonapiView extends BaseApiView
{
    /**
     * The fields to render item in the documents
     *
     * @var  array
     * @since  4.0.0
     */
    protected $fieldsToRenderItem = [
        'id',
        'typeAlias',
        'asset_id',
        'title',
        'note',
        'content',
        'ordering',
        'position',
        'checked_out',
        'checked_out_time',
        'publish_up',
        'publish_down',
        'published',
        'module',
        'access',
        'showtitle',
        'params',
        'client_id',
        'language',
        'assigned',
        'assignment',
        'xml',
    ];

    /**
     * The fields to render items in the documents
     *
     * @var  array
     * @since  4.0.0
     */
    protected $fieldsToRenderList = [
        'id',
        'title',
        'note',
        'position',
        'module',
        'language',
        'checked_out',
        'checked_out_time',
        'published',
        'enabled',
        'access',
        'ordering',
        'publish_up',
        'publish_down',
        'language_title',
        'language_image',
        'editor',
        'access_level',
        'pages',
        'name',
    ];

    /**
     * Execute and display a template script.
     *
     * @param   object  $item  Item
     *
     * @return  string
     *
     * @since   4.0.0
     */
    public function displayItem($item = null)
    {
        /** @var \Joomla\CMS\MVC\Model\AdminModel $model */
        $model = $this->getModel();

        if ($item === null) {
            $item  = $this->prepareItem($model->getItem());
        }

        if ($item->id === null) {
            throw new RouteNotFoundException('Item does not exist');
        }

        if ((int) $model->getState('client_id') !== $item->client_id) {
            throw new RouteNotFoundException('Item does not exist');
        }

        return parent::displayItem($item);
    }

    /**
     * Execute and display a list modules types.
     *
     * @return  string
     *
     * @since   4.0.0
     */
    public function displayListTypes()
    {
        /** @var SelectModel $model */
        $model = $this->getModel();
        $items = [];

        foreach ($model->getItems() as $item) {
            $item->id = $item->extension_id;
            unset($item->extension_id);

            $items[] = $item;
        }

        $this->fieldsToRenderList = ['id', 'name', 'module', 'xml', 'desc'];

        return parent::displayList($items);
    }
}

The same content is in 5 releases, Joomla 4.2.0-beta3 to 4.2.1-rc2. See them all, or every version of this file.