[ 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_workflow 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\Workflow\Administrator\Field; 12 13 use Joomla\CMS\Access\Access; 14 use Joomla\CMS\Factory; 15 use Joomla\CMS\Form\Field\ListField; 16 use Joomla\CMS\Language\Text; 17 use Joomla\CMS\Workflow\WorkflowServiceInterface; 18 use Joomla\Utilities\ArrayHelper; 19 20 // phpcs:disable PSR1.Files.SideEffects 21 \defined('_JEXEC') or die; 22 // phpcs:enable PSR1.Files.SideEffects 23 24 /** 25 * Components Workflow field. 26 * 27 * @since 1.6 28 */ 29 class ComponentsWorkflowField extends ListField 30 { 31 /** 32 * The form field type. 33 * 34 * @var string 35 * @since 3.7.0 36 */ 37 protected $type = 'ComponentsWorkflow'; 38 39 /** 40 * Method to get a list of options for a list input. 41 * 42 * @return array An array of JHtml options. 43 * 44 * @since 3.7.0 45 */ 46 protected function getOptions() 47 { 48 // Initialise variable. 49 $db = $this->getDatabase(); 50 51 $query = $db->getQuery(true) 52 ->select('DISTINCT a.name AS text, a.element AS value') 53 ->from('#__extensions as a') 54 ->where('a.enabled >= 1') 55 ->where('a.type =' . $db->quote('component')); 56 57 $items = $db->setQuery($query)->loadObjectList(); 58 59 $options = []; 60 61 if (count($items)) { 62 $lang = Factory::getLanguage(); 63 64 $components = []; 65 66 // Search for components supporting Fieldgroups - suppose that these components support fields as well 67 foreach ($items as &$item) { 68 $availableActions = Access::getActionsFromFile( 69 JPATH_ADMINISTRATOR . '/components/' . $item->value . '/access.xml', 70 "/access/section[@name='workflow']/" 71 ); 72 73 if (!empty($availableActions)) { 74 // Load language 75 $source = JPATH_ADMINISTRATOR . '/components/' . $item->value; 76 $lang->load($item->value . 'sys', JPATH_ADMINISTRATOR) 77 || $lang->load($item->value . 'sys', $source); 78 79 // Translate component name 80 $item->text = Text::_($item->text); 81 82 $components[] = $item; 83 } 84 } 85 86 if (empty($components)) { 87 return []; 88 } 89 90 foreach ($components as $component) { 91 // Search for different contexts 92 $c = Factory::getApplication()->bootComponent($component->value); 93 94 if ($c instanceof WorkflowServiceInterface) { 95 $contexts = $c->getContexts(); 96 97 foreach ($contexts as $context) { 98 $newOption = new \stdClass(); 99 $newOption->value = strtolower($component->value . '.' . $context); 100 $newOption->text = $component->text . ' - ' . Text::_($context); 101 $options[] = $newOption; 102 } 103 } else { 104 $options[] = $component; 105 } 106 } 107 108 // Sort by name 109 $items = ArrayHelper::sortObjects($options, 'text', 1, true, true); 110 } 111 112 // Merge any additional options in the XML definition. 113 $options = array_merge(parent::getOptions(), $items); 114 115 return $options; 116 } 117 }
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 |