[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.API 5 * @subpackage com_content 6 * 7 * @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Content\Api\Controller; 12 13 use Joomla\CMS\Filter\InputFilter; 14 use Joomla\CMS\MVC\Controller\ApiController; 15 use Joomla\Component\Fields\Administrator\Helper\FieldsHelper; 16 17 // phpcs:disable PSR1.Files.SideEffects 18 \defined('_JEXEC') or die; 19 // phpcs:enable PSR1.Files.SideEffects 20 21 /** 22 * The article controller 23 * 24 * @since 4.0.0 25 */ 26 class ArticlesController extends ApiController 27 { 28 /** 29 * The content type of the item. 30 * 31 * @var string 32 * @since 4.0.0 33 */ 34 protected $contentType = 'articles'; 35 36 /** 37 * The default view for the display method. 38 * 39 * @var string 40 * @since 3.0 41 */ 42 protected $default_view = 'articles'; 43 44 /** 45 * Article list view amended to add filtering of data 46 * 47 * @return static A BaseController object to support chaining. 48 * 49 * @since 4.0.0 50 */ 51 public function displayList() 52 { 53 $apiFilterInfo = $this->input->get('filter', [], 'array'); 54 $filter = InputFilter::getInstance(); 55 56 if (\array_key_exists('author', $apiFilterInfo)) { 57 $this->modelState->set('filter.author_id', $filter->clean($apiFilterInfo['author'], 'INT')); 58 } 59 60 if (\array_key_exists('category', $apiFilterInfo)) { 61 $this->modelState->set('filter.category_id', $filter->clean($apiFilterInfo['category'], 'INT')); 62 } 63 64 if (\array_key_exists('search', $apiFilterInfo)) { 65 $this->modelState->set('filter.search', $filter->clean($apiFilterInfo['search'], 'STRING')); 66 } 67 68 if (\array_key_exists('state', $apiFilterInfo)) { 69 $this->modelState->set('filter.published', $filter->clean($apiFilterInfo['state'], 'INT')); 70 } 71 72 if (\array_key_exists('language', $apiFilterInfo)) { 73 $this->modelState->set('filter.language', $filter->clean($apiFilterInfo['language'], 'STRING')); 74 } 75 76 $apiListInfo = $this->input->get('list', [], 'array'); 77 78 if (array_key_exists('ordering', $apiListInfo)) { 79 $this->modelState->set('list.ordering', $filter->clean($apiListInfo['ordering'], 'STRING')); 80 } 81 82 if (array_key_exists('direction', $apiListInfo)) { 83 $this->modelState->set('list.direction', $filter->clean($apiListInfo['direction'], 'STRING')); 84 } 85 86 return parent::displayList(); 87 } 88 89 /** 90 * Method to allow extended classes to manipulate the data to be saved for an extension. 91 * 92 * @param array $data An array of input data. 93 * 94 * @return array 95 * 96 * @since 4.0.0 97 */ 98 protected function preprocessSaveData(array $data): array 99 { 100 foreach (FieldsHelper::getFields('com_content.article') as $field) { 101 if (isset($data[$field->name])) { 102 !isset($data['com_fields']) && $data['com_fields'] = []; 103 104 $data['com_fields'][$field->name] = $data[$field->name]; 105 unset($data[$field->name]); 106 } 107 } 108 109 return $data; 110 } 111 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |