[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Joomla! Content Management System 5 * 6 * @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10 namespace Joomla\CMS\Form\Field; 11 12 use Joomla\CMS\Factory; 13 use Joomla\CMS\HTML\HTMLHelper; 14 use Joomla\CMS\Language\Text; 15 use Joomla\CMS\Log\Log; 16 17 // phpcs:disable PSR1.Files.SideEffects 18 \defined('JPATH_PLATFORM') or die; 19 // phpcs:enable PSR1.Files.SideEffects 20 21 /** 22 * Form Field class for the Joomla Platform. 23 * Supports an HTML select list of categories 24 * 25 * @since 1.6 26 */ 27 class CategoryField extends ListField 28 { 29 /** 30 * The form field type. 31 * 32 * @var string 33 * @since 1.6 34 */ 35 public $type = 'Category'; 36 37 /** 38 * Method to get the field options for category 39 * Use the extension attribute in a form to specify the.specific extension for 40 * which categories should be displayed. 41 * Use the show_root attribute to specify whether to show the global category root in the list. 42 * 43 * @return array The field option objects. 44 * 45 * @since 1.6 46 */ 47 protected function getOptions() 48 { 49 $options = array(); 50 $extension = $this->element['extension'] ? (string) $this->element['extension'] : (string) $this->element['scope']; 51 $published = (string) $this->element['published']; 52 $language = (string) $this->element['language']; 53 54 // Load the category options for a given extension. 55 if (!empty($extension)) { 56 // Filter over published state or not depending upon if it is present. 57 $filters = array(); 58 59 if ($published) { 60 $filters['filter.published'] = explode(',', $published); 61 } 62 63 // Filter over language depending upon if it is present. 64 if ($language) { 65 $filters['filter.language'] = explode(',', $language); 66 } 67 68 if ($filters === array()) { 69 $options = HTMLHelper::_('category.options', $extension); 70 } else { 71 $options = HTMLHelper::_('category.options', $extension, $filters); 72 } 73 74 // Verify permissions. If the action attribute is set, then we scan the options. 75 if ((string) $this->element['action']) { 76 // Get the current user object. 77 $user = Factory::getUser(); 78 79 foreach ($options as $i => $option) { 80 /* 81 * To take save or create in a category you need to have create rights for that category 82 * unless the item is already in that category. 83 * Unset the option if the user isn't authorised for it. In this field assets are always categories. 84 */ 85 if ($user->authorise('core.create', $extension . '.category.' . $option->value) === false) { 86 unset($options[$i]); 87 } 88 } 89 } 90 91 if (isset($this->element['show_root'])) { 92 array_unshift($options, HTMLHelper::_('select.option', '0', Text::_('JGLOBAL_ROOT'))); 93 } 94 } else { 95 Log::add(Text::_('JLIB_FORM_ERROR_FIELDS_CATEGORY_ERROR_EXTENSION_EMPTY'), Log::WARNING, 'jerror'); 96 } 97 98 // Merge any additional options in the XML definition. 99 $options = array_merge(parent::getOptions(), $options); 100 101 return $options; 102 } 103 }
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 |