[ 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\Rule; 11 12 use Joomla\CMS\Access\Access; 13 use Joomla\CMS\Form\Form; 14 use Joomla\CMS\Form\FormRule; 15 use Joomla\Registry\Registry; 16 17 // phpcs:disable PSR1.Files.SideEffects 18 \defined('JPATH_PLATFORM') or die; 19 // phpcs:enable PSR1.Files.SideEffects 20 21 /** 22 * Form Rule class for the Joomla Platform. 23 * 24 * @since 1.7.0 25 */ 26 class RulesRule extends FormRule 27 { 28 /** 29 * Method to test the value. 30 * 31 * @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object. 32 * @param mixed $value The form field value to validate. 33 * @param string $group The field name group control value. This acts as an array container for the field. 34 * For example if the field has name="foo" and the group value is set to "bar" then the 35 * full field name would end up being "bar[foo]". 36 * @param Registry $input An optional Registry object with the entire data set to validate against the entire form. 37 * @param Form $form The form object for which the field is being tested. 38 * 39 * @return boolean True if the value is valid, false otherwise. 40 * 41 * @since 1.7.0 42 */ 43 public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null) 44 { 45 // Get the possible field actions and the ones posted to validate them. 46 $fieldActions = self::getFieldActions($element); 47 $valueActions = self::getValueActions($value); 48 49 // Make sure that all posted actions are in the list of possible actions for the field. 50 foreach ($valueActions as $action) { 51 if (!\in_array($action, $fieldActions)) { 52 return false; 53 } 54 } 55 56 return true; 57 } 58 59 /** 60 * Method to get the list of permission action names from the form field value. 61 * 62 * @param mixed $value The form field value to validate. 63 * 64 * @return array A list of permission action names from the form field value. 65 * 66 * @since 1.7.0 67 */ 68 protected function getValueActions($value) 69 { 70 $actions = array(); 71 72 // Iterate over the asset actions and add to the actions. 73 foreach ((array) $value as $name => $rules) { 74 $actions[] = $name; 75 } 76 77 return $actions; 78 } 79 80 /** 81 * Method to get the list of possible permission action names for the form field. 82 * 83 * @param \SimpleXMLElement $element The \SimpleXMLElement object representing the `<field>` tag for the form field object. 84 * 85 * @return array A list of permission action names from the form field element definition. 86 * 87 * @since 1.7.0 88 */ 89 protected function getFieldActions(\SimpleXMLElement $element) 90 { 91 $actions = array(); 92 93 // Initialise some field attributes. 94 $section = $element['section'] ? (string) $element['section'] : ''; 95 $component = $element['component'] ? (string) $element['component'] : ''; 96 97 // Get the asset actions for the element. 98 $elActions = Access::getActionsFromFile( 99 JPATH_ADMINISTRATOR . '/components/' . $component . '/access.xml', 100 "/access/section[@name='" . $section . "']/" 101 ); 102 103 if ($elActions) { 104 // Iterate over the asset actions and add to the actions. 105 foreach ($elActions as $item) { 106 $actions[] = $item->name; 107 } 108 } 109 110 // Iterate over the children and add to the actions. 111 foreach ($element->children() as $el) { 112 if ($el->getName() === 'action') { 113 $actions[] = (string) $el['name']; 114 } 115 } 116 117 return $actions; 118 } 119 }
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 |