[ 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) 2011 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\Language\Text; 14 use Joomla\CMS\Log\Log; 15 16 // phpcs:disable PSR1.Files.SideEffects 17 \defined('JPATH_PLATFORM') or die; 18 // phpcs:enable PSR1.Files.SideEffects 19 20 /** 21 * Form Field class for the Joomla Framework. 22 * 23 * @since 2.5.0 24 */ 25 class PluginsField extends ListField 26 { 27 /** 28 * The field type. 29 * 30 * @var string 31 * @since 2.5.0 32 */ 33 protected $type = 'Plugins'; 34 35 /** 36 * The path to folder for plugins. 37 * 38 * @var string 39 * @since 3.2 40 */ 41 protected $folder; 42 43 /** 44 * Method to get certain otherwise inaccessible properties from the form field object. 45 * 46 * @param string $name The property name for which to get the value. 47 * 48 * @return mixed The property value or null. 49 * 50 * @since 3.2 51 */ 52 public function __get($name) 53 { 54 if ($name === 'folder') { 55 return $this->folder; 56 } 57 58 return parent::__get($name); 59 } 60 61 /** 62 * Method to set certain otherwise inaccessible properties of the form field object. 63 * 64 * @param string $name The property name for which to set the value. 65 * @param mixed $value The value of the property. 66 * 67 * @return void 68 * 69 * @since 3.2 70 */ 71 public function __set($name, $value) 72 { 73 switch ($name) { 74 case 'folder': 75 $this->folder = (string) $value; 76 break; 77 78 default: 79 parent::__set($name, $value); 80 } 81 } 82 83 /** 84 * Method to attach a Form object to the field. 85 * 86 * @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object. 87 * @param mixed $value The form field value to validate. 88 * @param string $group The field name group control value. This acts as an array container for the field. 89 * For example if the field has name="foo" and the group value is set to "bar" then the 90 * full field name would end up being "bar[foo]". 91 * 92 * @return boolean True on success. 93 * 94 * @see FormField::setup() 95 * @since 3.2 96 */ 97 public function setup(\SimpleXMLElement $element, $value, $group = null) 98 { 99 $return = parent::setup($element, $value, $group); 100 101 if ($return) { 102 $this->folder = (string) $this->element['folder']; 103 } 104 105 return $return; 106 } 107 108 /** 109 * Method to get a list of options for a list input. 110 * 111 * @return array An array of JHtml options. 112 * 113 * @since 2.5.0 114 */ 115 protected function getOptions() 116 { 117 $folder = $this->folder; 118 $parentOptions = parent::getOptions(); 119 120 if (!empty($folder)) { 121 // Get list of plugins 122 $db = $this->getDatabase(); 123 $query = $db->getQuery(true) 124 ->select( 125 [ 126 $db->quoteName('element', 'value'), 127 $db->quoteName('name', 'text'), 128 ] 129 ) 130 ->from($db->quoteName('#__extensions')) 131 ->where( 132 [ 133 $db->quoteName('folder') . ' = :folder', 134 $db->quoteName('enabled') . ' = 1', 135 ] 136 ) 137 ->bind(':folder', $folder) 138 ->order( 139 [ 140 $db->quoteName('ordering'), 141 $db->quoteName('name'), 142 ] 143 ); 144 145 if ((string) $this->element['useaccess'] === 'true') { 146 $query->whereIn($db->quoteName('access'), Factory::getUser()->getAuthorisedViewLevels()); 147 } 148 149 $options = $db->setQuery($query)->loadObjectList(); 150 $lang = Factory::getLanguage(); 151 $useGlobal = $this->element['useglobal']; 152 153 if ($useGlobal) { 154 $globalValue = Factory::getApplication()->get($this->fieldname); 155 } 156 157 foreach ($options as $i => $item) { 158 $source = JPATH_PLUGINS . '/' . $folder . '/' . $item->value; 159 $extension = 'plg_' . $folder . '_' . $item->value; 160 $lang->load($extension . '.sys', JPATH_ADMINISTRATOR) || $lang->load($extension . '.sys', $source); 161 $options[$i]->text = Text::_($item->text); 162 163 // If we are using useglobal update the use global value text with the plugin text. 164 if ($useGlobal && isset($parentOptions[0]) && $item->value === $globalValue) { 165 $text = Text::_($extension); 166 $parentOptions[0]->text = Text::sprintf('JGLOBAL_USE_GLOBAL_VALUE', ($text === '' || $text === $extension ? $item->value : $text)); 167 } 168 } 169 } else { 170 Log::add(Text::_('JFRAMEWORK_FORM_FIELDS_PLUGINS_ERROR_FOLDER_EMPTY'), Log::WARNING, 'jerror'); 171 } 172 173 return array_merge($parentOptions, $options); 174 } 175 }
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 |