- md5
- 2989ccdebaba54004b3b63c2df20fc56
- sha1
- 567a769c5bc8663a67d6e88a38929b91abb83f55
- sha256
- bb8361456b8cb8e1dadebc63790fa7371025f287579f2d5f2e04277740683ac9
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
<?php
/**
* @package Joomla.API
* @subpackage com_content
*
* @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\Content\Api\Controller;
\defined('_JEXEC') or die;
use Joomla\CMS\Filter\InputFilter;
use Joomla\CMS\MVC\Controller\ApiController;
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
/**
* The article controller
*
* @since 4.0.0
*/
class ArticlesController extends ApiController
{
/**
* The content type of the item.
*
* @var string
* @since 4.0.0
*/
protected $contentType = 'articles';
/**
* The default view for the display method.
*
* @var string
* @since 3.0
*/
protected $default_view = 'articles';
/**
* Article list view amended to add filtering of data
*
* @return static A BaseController object to support chaining.
*
* @since 4.0.0
*/
public function displayList()
{
$apiFilterInfo = $this->input->get('filter', [], 'array');
$filter = InputFilter::getInstance();
if (array_key_exists('author', $apiFilterInfo))
{
$this->modelState->set('filter.author_id', $filter->clean($apiFilterInfo['author'], 'INT'));
}
if (array_key_exists('category', $apiFilterInfo))
{
$this->modelState->set('filter.category_id', $filter->clean($apiFilterInfo['category'], 'INT'));
}
if (array_key_exists('search', $apiFilterInfo))
{
$this->modelState->set('filter.search', $filter->clean($apiFilterInfo['search'], 'STRING'));
}
if (array_key_exists('state', $apiFilterInfo))
{
$this->modelState->set('filter.published', $filter->clean($apiFilterInfo['state'], 'INT'));
}
if (array_key_exists('language', $apiFilterInfo))
{
$this->modelState->set('filter.language', $filter->clean($apiFilterInfo['language'], 'STRING'));
}
return parent::displayList();
}
/**
* Method to save a record.
*
* @param integer $recordKey The primary key of the item (if exists)
*
* @return integer The record ID on success, false on failure
*
* @since 4.0.0
*/
protected function save($recordKey = null)
{
$data = (array) json_decode($this->input->json->getRaw(), true);
foreach (FieldsHelper::getFields('com_content.article') as $field)
{
if (isset($data[$field->name]))
{
!isset($data['com_fields']) && $data['com_fields'] = [];
$data['com_fields'][$field->name] = $data[$field->name];
unset($data[$field->name]);
}
}
$this->input->set('data', $data);
return parent::save($recordKey);
}
}
The same content is in 2 releases, Joomla 4.0.0-beta6 to 4.0.0-beta7. See them all, or every version of this file.