[ 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) 2013 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\Access\Access; 13 use Joomla\CMS\Helper\UserGroupsHelper; 14 15 // phpcs:disable PSR1.Files.SideEffects 16 \defined('JPATH_PLATFORM') or die; 17 // phpcs:enable PSR1.Files.SideEffects 18 19 /** 20 * Field to load a dropdown list of available user groups 21 * 22 * @since 3.2 23 */ 24 class UsergrouplistField extends ListField 25 { 26 /** 27 * The form field type. 28 * 29 * @var string 30 * @since 3.2 31 */ 32 protected $type = 'UserGroupList'; 33 34 /** 35 * Cached array of the category items. 36 * 37 * @var array 38 * @since 3.2 39 */ 40 protected static $options = array(); 41 42 /** 43 * Method to attach a Form object to the field. 44 * 45 * @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object. 46 * @param mixed $value The form field value to validate. 47 * @param string $group The field name group control value. This acts as an array container for the field. 48 * For example if the field has name="foo" and the group value is set to "bar" then the 49 * full field name would end up being "bar[foo]". 50 * 51 * @return boolean True on success. 52 * 53 * @since 1.7.0 54 */ 55 public function setup(\SimpleXMLElement $element, $value, $group = null) 56 { 57 if (\is_string($value) && strpos($value, ',') !== false) { 58 $value = explode(',', $value); 59 } 60 61 return parent::setup($element, $value, $group); 62 } 63 64 /** 65 * Method to get the options to populate list 66 * 67 * @return array The field option objects. 68 * 69 * @since 3.2 70 */ 71 protected function getOptions() 72 { 73 $options = parent::getOptions(); 74 $checkSuperUser = (int) $this->getAttribute('checksuperusergroup', 0); 75 76 // Cache user groups base on checksuperusergroup attribute value 77 if (!isset(static::$options[$checkSuperUser])) { 78 $groups = UserGroupsHelper::getInstance()->getAll(); 79 $cacheOptions = array(); 80 81 foreach ($groups as $group) { 82 // Don't list super user groups. 83 if ($checkSuperUser && Access::checkGroup($group->id, 'core.admin')) { 84 continue; 85 } 86 87 $cacheOptions[] = (object) array( 88 'text' => str_repeat('- ', $group->level) . $group->title, 89 'value' => $group->id, 90 'level' => $group->level, 91 ); 92 } 93 94 static::$options[$checkSuperUser] = $cacheOptions; 95 } 96 97 return array_merge($options, static::$options[$checkSuperUser]); 98 } 99 }
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 |