[ 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) 2018 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\Workflow\WorkflowServiceInterface; 15 16 // phpcs:disable PSR1.Files.SideEffects 17 \defined('_JEXEC') or die; 18 // phpcs:enable PSR1.Files.SideEffects 19 20 /** 21 * Workflow States field. 22 * 23 * @since 4.0.0 24 */ 25 class WorkflowconditionField extends ListField 26 { 27 /** 28 * The form field type. 29 * 30 * @var string 31 * @since 4.0.0 32 */ 33 protected $type = 'Workflowcondition'; 34 35 /** 36 * The component and section separated by ".". 37 * 38 * @var string 39 * @since 4.0.0 40 */ 41 protected $extension = ''; 42 43 /** 44 * Determinate if the "All" value should be added 45 * 46 * @var boolean 47 * @since 4.0.0 48 */ 49 protected $hideAll = false; 50 51 /** 52 * Method to attach a Form object to the field. 53 * 54 * @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object. 55 * @param mixed $value The form field value to validate. 56 * @param string $group The field name group control value. This acts as as an array container for the field. 57 * For example if the field has name="foo" and the group value is set to "bar" then the 58 * full field name would end up being "bar[foo]". 59 * 60 * @return boolean True on success. 61 * 62 * @since 4.0.0 63 */ 64 public function setup(\SimpleXMLElement $element, $value, $group = null) 65 { 66 $success = parent::setup($element, $value, $group); 67 68 if ($success) { 69 if (\strlen($element['extension'])) { 70 $this->extension = (string) $element['extension']; 71 } else { 72 $this->extension = Factory::getApplication()->input->getCmd('extension'); 73 } 74 75 if (\strlen($element['hide_all'])) { 76 $this->hideAll = (string) $element['hide_all'] === 'true' || (string) $element['hide_all'] === 'yes'; 77 } 78 } 79 80 return $success; 81 } 82 83 /** 84 * Method to get the field options. 85 * 86 * @return array The field option objects. 87 * 88 * @since 4.0.0 89 */ 90 protected function getOptions() 91 { 92 $fieldname = preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname); 93 $options = []; 94 $conditions = []; 95 96 $parts = explode('.', $this->extension); 97 98 $component = Factory::getApplication()->bootComponent($parts[0]); 99 100 if ($component instanceof WorkflowServiceInterface) { 101 $conditions = $component->getConditions($this->extension); 102 } 103 104 foreach ($conditions as $value => $option) { 105 $text = trim((string) $option) != '' ? trim((string) $option) : $value; 106 107 $selected = ((int) $this->value === $value); 108 109 $tmp = array( 110 'value' => $value, 111 'text' => Text::alt($text, $fieldname), 112 'selected' => $selected, 113 'checked' => $selected, 114 ); 115 116 // Add the option object to the result set. 117 $options[] = (object) $tmp; 118 } 119 120 if (!$this->hideAll) { 121 $options[] = (object) array( 122 'value' => '*', 123 'text' => Text::_('JALL'), 124 'selected' => $this->value === '*', 125 'checked' => $this->value === '*', 126 ); 127 } 128 129 // Merge any additional options in the XML definition. 130 return array_merge(parent::getOptions(), $options); 131 } 132 }
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 |