[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_content 6 * 7 * @copyright (C) 2018 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\Administrator\Extension; 12 13 use Joomla\CMS\Application\SiteApplication; 14 use Joomla\CMS\Association\AssociationServiceInterface; 15 use Joomla\CMS\Association\AssociationServiceTrait; 16 use Joomla\CMS\Categories\CategoryServiceInterface; 17 use Joomla\CMS\Categories\CategoryServiceTrait; 18 use Joomla\CMS\Component\Router\RouterServiceInterface; 19 use Joomla\CMS\Component\Router\RouterServiceTrait; 20 use Joomla\CMS\Extension\BootableExtensionInterface; 21 use Joomla\CMS\Extension\MVCComponent; 22 use Joomla\CMS\Factory; 23 use Joomla\CMS\Fields\FieldsServiceInterface; 24 use Joomla\CMS\Form\Form; 25 use Joomla\CMS\Helper\ContentHelper as LibraryContentHelper; 26 use Joomla\CMS\HTML\HTMLRegistryAwareTrait; 27 use Joomla\CMS\Language\Text; 28 use Joomla\CMS\Tag\TagServiceInterface; 29 use Joomla\CMS\Tag\TagServiceTrait; 30 use Joomla\CMS\Workflow\WorkflowServiceInterface; 31 use Joomla\CMS\Workflow\WorkflowServiceTrait; 32 use Joomla\Component\Content\Administrator\Helper\ContentHelper; 33 use Joomla\Component\Content\Administrator\Service\HTML\AdministratorService; 34 use Joomla\Component\Content\Administrator\Service\HTML\Icon; 35 use Psr\Container\ContainerInterface; 36 37 // phpcs:disable PSR1.Files.SideEffects 38 \defined('JPATH_PLATFORM') or die; 39 // phpcs:enable PSR1.Files.SideEffects 40 41 /** 42 * Component class for com_content 43 * 44 * @since 4.0.0 45 */ 46 class ContentComponent extends MVCComponent implements 47 BootableExtensionInterface, 48 CategoryServiceInterface, 49 FieldsServiceInterface, 50 AssociationServiceInterface, 51 WorkflowServiceInterface, 52 RouterServiceInterface, 53 TagServiceInterface 54 { 55 use AssociationServiceTrait; 56 use RouterServiceTrait; 57 use HTMLRegistryAwareTrait; 58 use WorkflowServiceTrait; 59 use CategoryServiceTrait, TagServiceTrait { 60 CategoryServiceTrait::getTableNameForSection insteadof TagServiceTrait; 61 CategoryServiceTrait::getStateColumnForSection insteadof TagServiceTrait; 62 } 63 64 /** @var array Supported functionality */ 65 protected $supportedFunctionality = [ 66 'core.featured' => true, 67 'core.state' => true, 68 ]; 69 70 /** 71 * The trashed condition 72 * 73 * @since 4.0.0 74 */ 75 public const CONDITION_NAMES = [ 76 self::CONDITION_PUBLISHED => 'JPUBLISHED', 77 self::CONDITION_UNPUBLISHED => 'JUNPUBLISHED', 78 self::CONDITION_ARCHIVED => 'JARCHIVED', 79 self::CONDITION_TRASHED => 'JTRASHED', 80 ]; 81 82 /** 83 * The archived condition 84 * 85 * @since 4.0.0 86 */ 87 public const CONDITION_ARCHIVED = 2; 88 89 /** 90 * The published condition 91 * 92 * @since 4.0.0 93 */ 94 public const CONDITION_PUBLISHED = 1; 95 96 /** 97 * The unpublished condition 98 * 99 * @since 4.0.0 100 */ 101 public const CONDITION_UNPUBLISHED = 0; 102 103 /** 104 * The trashed condition 105 * 106 * @since 4.0.0 107 */ 108 public const CONDITION_TRASHED = -2; 109 110 /** 111 * Booting the extension. This is the function to set up the environment of the extension like 112 * registering new class loaders, etc. 113 * 114 * If required, some initial set up can be done from services of the container, eg. 115 * registering HTML services. 116 * 117 * @param ContainerInterface $container The container 118 * 119 * @return void 120 * 121 * @since 4.0.0 122 */ 123 public function boot(ContainerInterface $container) 124 { 125 $this->getRegistry()->register('contentadministrator', new AdministratorService()); 126 $this->getRegistry()->register('contenticon', new Icon()); 127 128 // The layout joomla.content.icons does need a general icon service 129 $this->getRegistry()->register('icon', $this->getRegistry()->getService('contenticon')); 130 } 131 132 /** 133 * Returns a valid section for the given section. If it is not valid then null 134 * is returned. 135 * 136 * @param string $section The section to get the mapping for 137 * @param object $item The item 138 * 139 * @return string|null The new section 140 * 141 * @since 4.0.0 142 */ 143 public function validateSection($section, $item = null) 144 { 145 if (Factory::getApplication()->isClient('site')) { 146 // On the front end we need to map some sections 147 switch ($section) { 148 // Editing an article 149 case 'form': 150 // Category list view 151 case 'featured': 152 case 'category': 153 $section = 'article'; 154 } 155 } 156 157 if ($section != 'article') { 158 // We don't know other sections 159 return null; 160 } 161 162 return $section; 163 } 164 165 /** 166 * Returns valid contexts 167 * 168 * @return array 169 * 170 * @since 4.0.0 171 */ 172 public function getContexts(): array 173 { 174 Factory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR); 175 176 $contexts = array( 177 'com_content.article' => Text::_('COM_CONTENT'), 178 'com_content.categories' => Text::_('JCATEGORY') 179 ); 180 181 return $contexts; 182 } 183 184 /** 185 * Returns valid contexts 186 * 187 * @return array 188 * 189 * @since 4.0.0 190 */ 191 public function getWorkflowContexts(): array 192 { 193 Factory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR); 194 195 $contexts = array( 196 'com_content.article' => Text::_('COM_CONTENT') 197 ); 198 199 return $contexts; 200 } 201 202 /** 203 * Returns the workflow context based on the given category section 204 * 205 * @param string $section The section 206 * 207 * @return string|null 208 * 209 * @since 4.0.0 210 */ 211 public function getCategoryWorkflowContext(?string $section = null): string 212 { 213 $context = $this->getWorkflowContexts(); 214 215 return array_key_first($context); 216 } 217 218 /** 219 * Returns the table for the count items functions for the given section. 220 * 221 * @param string $section The section 222 * 223 * @return string|null 224 * 225 * @since 4.0.0 226 */ 227 protected function getTableNameForSection(string $section = null) 228 { 229 return '#__content'; 230 } 231 232 /** 233 * Returns a table name for the state association 234 * 235 * @param string $section An optional section to separate different areas in the component 236 * 237 * @return string 238 * 239 * @since 4.0.0 240 */ 241 public function getWorkflowTableBySection(?string $section = null): string 242 { 243 return '#__content'; 244 } 245 246 /** 247 * Returns the model name, based on the context 248 * 249 * @param string $context The context of the workflow 250 * 251 * @return string 252 */ 253 public function getModelName($context): string 254 { 255 $parts = explode('.', $context); 256 257 if (count($parts) < 2) { 258 return ''; 259 } 260 261 array_shift($parts); 262 263 $modelname = array_shift($parts); 264 265 if ($modelname === 'article' && Factory::getApplication()->isClient('site')) { 266 return 'Form'; 267 } elseif ($modelname === 'featured' && Factory::getApplication()->isClient('administrator')) { 268 return 'Article'; 269 } 270 271 return ucfirst($modelname); 272 } 273 274 /** 275 * Method to filter transitions by given id of state. 276 * 277 * @param array $transitions The Transitions to filter 278 * @param int $pk Id of the state 279 * 280 * @return array 281 * 282 * @since 4.0.0 283 */ 284 public function filterTransitions(array $transitions, int $pk): array 285 { 286 return ContentHelper::filterTransitions($transitions, $pk); 287 } 288 289 /** 290 * Adds Count Items for Category Manager. 291 * 292 * @param \stdClass[] $items The category objects 293 * @param string $section The section 294 * 295 * @return void 296 * 297 * @since 4.0.0 298 */ 299 public function countItems(array $items, string $section) 300 { 301 $config = (object) array( 302 'related_tbl' => 'content', 303 'state_col' => 'state', 304 'group_col' => 'catid', 305 'relation_type' => 'category_or_group', 306 'uses_workflows' => true, 307 'workflows_component' => 'com_content' 308 ); 309 310 LibraryContentHelper::countRelations($items, $config); 311 } 312 313 /** 314 * Adds Count Items for Tag Manager. 315 * 316 * @param \stdClass[] $items The content objects 317 * @param string $extension The name of the active view. 318 * 319 * @return void 320 * 321 * @since 4.0.0 322 * @throws \Exception 323 */ 324 public function countTagItems(array $items, string $extension) 325 { 326 $parts = explode('.', $extension); 327 $section = count($parts) > 1 ? $parts[1] : null; 328 329 $config = (object) array( 330 'related_tbl' => ($section === 'category' ? 'categories' : 'content'), 331 'state_col' => ($section === 'category' ? 'published' : 'state'), 332 'group_col' => 'tag_id', 333 'extension' => $extension, 334 'relation_type' => 'tag_assigments', 335 ); 336 337 LibraryContentHelper::countRelations($items, $config); 338 } 339 340 /** 341 * Prepares the category form 342 * 343 * @param Form $form The form to prepare 344 * @param array|object $data The form data 345 * 346 * @return void 347 */ 348 public function prepareForm(Form $form, $data) 349 { 350 ContentHelper::onPrepareForm($form, $data); 351 } 352 }
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 |