- md5
- 86d4a15c4df21d0719a732cbfdb1c375
- sha1
- 45a9325ed7809b8984abe25fcc11e24cb2d9a4d3
- sha256
- 220877254f571a3a683fab5853ff668b728f29271f78290921f62cdc0b6f3375
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 20 releases, Joomla 4.1.0-rc2 to 4.2.0-beta2. See them all, or every version of this file.