- md5
- bcd320e7519ff40934494ef02df18d7a
- sha1
- ecba3a1fae1e6e69839ca0fde5d77ab85da2110e
- sha256
- beac1814b7f9bf88dc1224a2007203480f880a59b140ebc3e3ad9f7b6567f684
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
<?php
/**
* @package Joomla.API
* @subpackage com_languages
*
* @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\Languages\Api\View\Strings;
\defined('_JEXEC') or die;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\JsonApiView as BaseApiView;
use Joomla\CMS\Serializer\JoomlaSerializer;
use Tobscure\JsonApi\Collection;
/**
* The strings view
*
* @since 4.0.0
*/
class JsonapiView extends BaseApiView
{
/**
* The fields to render items in the documents
*
* @var array
* @since 4.0.0
*/
protected $fieldsToRenderList = [
'id',
'string',
'file',
];
/**
* Execute and display a template script.
*
* @param array|null $items Array of items
*
* @return string
*
* @since 4.0.0
*/
public function displayList(array $items = null)
{
/** @var \Joomla\Component\Languages\Administrator\Model\StringsModel $model */
$model = $this->getModel();
$result = $model->search();
if ($result instanceof \Exception)
{
throw $result;
}
$items = [];
foreach ($result['results'] as $item)
{
$items[] = $this->prepareItem($item);
}
// Check for errors.
if (count($errors = $this->get('Errors')))
{
throw new GenericDataException(implode("\n", $errors), 500);
}
if ($this->type === null)
{
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_CONTENT_TYPE_MISSING'), 400);
}
$collection = (new Collection($items, new JoomlaSerializer($this->type)))
->fields([$this->type => $this->fieldsToRenderList]);
// Set the data into the document and render it
$this->document->setData($collection);
return $this->document->render();
}
/**
* Prepare item before render.
*
* @param object $item The model item
*
* @return object
*
* @since 4.0.0
*/
protected function prepareItem($item)
{
$item->id = $item->constant;
unset($item->constant);
return parent::prepareItem($item);
}
}
The same content is in 31 releases, Joomla 4.0.0-beta6 to 4.1.0-rc1. See them all, or every version of this file.