- md5
- e371dd3051274c768a4e2ec8a7f0f26a
- sha1
- 2f2d2ecf867cf0f776adf62cc7de221201faf3b3
- sha256
- c8c9875380426b8f2c3154c78402b5b5fd1b24603f1ed4f00b986505375d2f16
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
<?php
/**
* @package Joomla.API
* @subpackage com_content
*
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Content\Api\View\Articles;
\defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\MVC\View\JsonApiView as BaseApiView;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Component\Content\Api\Helper\ContentHelper;
use Joomla\Component\Content\Api\Serializer\ContentSerializer;
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
use Joomla\Registry\Registry;
/**
* The article 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',
'text',
'tags',
'language',
'state',
'category',
'created',
'author',
'images',
];
/**
* The fields to render items in the documents
*
* @var array
* @since 4.0.0
*/
protected $fieldsToRenderList = [
'id',
'typeAlias',
'asset_id',
'title',
'text',
'tags',
'language',
'state',
'category',
'created',
'author',
'images',
];
/**
* The relationships the item has
*
* @var array
* @since 4.0.0
*/
protected $relationship = [
'category',
'author',
];
/**
* Constructor.
*
* @param array $config A named configuration array for object construction.
* contentType: the name (optional) of the content type to use for the serialization
*
* @since 4.0.0
*/
public function __construct($config = [])
{
if (array_key_exists('contentType', $config))
{
$this->serializer = new ContentSerializer($config['contentType']);
}
parent::__construct($config);
}
/**
* 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)
{
foreach (FieldsHelper::getFields('com_content.article') as $field)
{
$this->fieldsToRenderList[] = $field->name;
}
return parent::displayList();
}
/**
* Execute and display a template script.
*
* @param object $item Item
*
* @return string
*
* @since 4.0.0
*/
public function displayItem($item = null)
{
foreach (FieldsHelper::getFields('com_content.article') as $field)
{
$this->fieldsToRenderItem[] = $field->name;
}
if (Multilanguage::isEnabled())
{
$this->fieldsToRenderItem[] = 'languageAssociations';
$this->relationship[] = 'languageAssociations';
}
return parent::displayItem();
}
/**
* Prepare item before render.
*
* @param object $item The model item
*
* @return object
*
* @since 4.0.0
*/
protected function prepareItem($item)
{
$item->text = $item->introtext . ' ' . $item->fulltext;
// Process the content plugins.
PluginHelper::importPlugin('content');
Factory::getApplication()->triggerEvent('onContentPrepare', ['com_content.article', &$item, &$item->params]);
foreach (FieldsHelper::getFields('com_content.article', $item, true) as $field)
{
$item->{$field->name} = isset($field->apivalue) ? $field->apivalue : $field->rawvalue;
}
if (Multilanguage::isEnabled() && !empty($item->associations))
{
$associations = [];
foreach ($item->associations as $language => $association)
{
$itemId = explode(':', $association)[0];
$associations[] = (object) [
'id' => $itemId,
'language' => $language,
];
}
$item->associations = $associations;
}
if (!empty($item->tags->tags))
{
$tagsIds = explode(',', $item->tags->tags);
$tagsNames = $item->tagsHelper->getTagNames($tagsIds);
$item->tags = array_combine($tagsIds, $tagsNames);
}
else
{
$item->tags = [];
}
if (isset($item->images))
{
$registry = new Registry($item->images);
$item->images = $registry->toArray();
if (!empty($item->images['image_intro']))
{
$item->images['image_intro'] = ContentHelper::resolve($item->images['image_intro']);
}
if (!empty($item->images['image_fulltext']))
{
$item->images['image_fulltext'] = ContentHelper::resolve($item->images['image_fulltext']);
}
}
return parent::prepareItem($item);
}
}
No other release has this exact content. See every version of this file.