[ 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) 2020 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE 8 */ 9 10 namespace Joomla\CMS\Workflow; 11 12 use Joomla\CMS\Form\Form; 13 use Joomla\CMS\Object\CMSObject; 14 use ReflectionClass; 15 16 // phpcs:disable PSR1.Files.SideEffects 17 \defined('JPATH_PLATFORM') or die; 18 // phpcs:enable PSR1.Files.SideEffects 19 20 /** 21 * Trait for component workflow plugins. 22 * 23 * @since 4.0.0 24 */ 25 trait WorkflowPluginTrait 26 { 27 /** 28 * Add different parameter options to the transition view, we need when executing the transition 29 * 30 * @param Form $form The form 31 * @param \stdClass $data The data 32 * 33 * @return boolean 34 * 35 * @since 4.0.0 36 */ 37 protected function enhanceWorkflowTransitionForm(Form $form, $data) 38 { 39 $workflow_id = (int) ($data->workflow_id ?? $form->getValue('workflow_id')); 40 41 $workflow = $this->getWorkflow($workflow_id); 42 43 if (empty($workflow->id) || !$this->isSupported($workflow->extension)) { 44 return false; 45 } 46 47 // Load XML file from "parent" plugin 48 $path = dirname((new ReflectionClass(static::class))->getFileName()); 49 50 if (is_file($path . '/forms/action.xml')) { 51 $form->loadFile($path . '/forms/action.xml'); 52 } 53 54 return $workflow; 55 } 56 57 /** 58 * Get the workflow for a given ID 59 * 60 * @param int|null $workflowId ID of the workflow 61 * 62 * @return CMSObject|boolean Object on success, false on failure. 63 * 64 * @since 4.0.0 65 */ 66 protected function getWorkflow(int $workflowId = null) 67 { 68 $workflowId = !empty($workflowId) ? $workflowId : $this->app->input->getInt('workflow_id'); 69 70 if (is_array($workflowId)) { 71 return false; 72 } 73 74 return $this->app->bootComponent('com_workflow') 75 ->getMVCFactory() 76 ->createModel('Workflow', 'Administrator', ['ignore_request' => true]) 77 ->getItem($workflowId); 78 } 79 80 /** 81 * Check if the current plugin should execute workflow related activities 82 * 83 * @param string $context Context to check 84 * 85 * @return boolean 86 * 87 * @since 4.0.0 88 */ 89 protected function isSupported($context) 90 { 91 return false; 92 } 93 94 /** 95 * Check if the context is listed in the allowed of forbidden lists and return the result. 96 * 97 * @param string $context Context to check 98 * 99 * @return boolean 100 */ 101 protected function checkAllowedAndForbiddenlist($context) 102 { 103 $allowedlist = \array_filter((array) $this->params->get('allowedlist', [])); 104 $forbiddenlist = \array_filter((array) $this->params->get('forbiddenlist', [])); 105 106 if (!empty($allowedlist)) { 107 foreach ($allowedlist as $allowed) { 108 if ($context === $allowed) { 109 return true; 110 } 111 } 112 113 return false; 114 } 115 116 foreach ($forbiddenlist as $forbidden) { 117 if ($context === $forbidden) { 118 return false; 119 } 120 } 121 122 return true; 123 } 124 125 /** 126 * Check if the context supports a specific functionality. 127 * 128 * @param string $context Context to check 129 * @param string $functionality The functionality 130 * 131 * @return boolean 132 */ 133 protected function checkExtensionSupport($context, $functionality) 134 { 135 $parts = explode('.', $context); 136 137 $component = $this->app->bootComponent($parts[0]); 138 139 if ( 140 !$component instanceof WorkflowServiceInterface 141 || !$component->isWorkflowActive($context) 142 || !$component->supportFunctionality($functionality, $context) 143 ) { 144 return false; 145 } 146 147 return true; 148 } 149 }
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 |