- md5
- acd37e135640ec2da89375e388e22e41
- sha1
- b2be44c879354ccd1fc655d6905bbc10626b2144
- sha256
- 74653f048fe34e588068e795d87f2477eb00a235160e502271d1a53a23847f2e
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
<?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\CMS\Workflow;
\defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Object\CMSObject;
use ReflectionClass;
/**
* Trait for component workflow plugins.
*
* @since 4.0.0
*/
trait WorkflowPluginTrait
{
/**
* Add different parameter options to the transition view, we need when executing the transition
*
* @param Form $form The form
* @param \stdClass $data The data
*
* @return boolean
*
* @since 4.0.0
*/
protected function enhanceWorkflowTransitionForm(Form $form, $data)
{
$workflow_id = (int) ($data->workflow_id ?? $form->getValue('workflow_id'));
$workflow = $this->getWorkflow($workflow_id);
if (empty($workflow->id) || !$this->isSupported($workflow->extension))
{
return false;
}
// Load XML file from "parent" plugin
$path = dirname((new ReflectionClass(static::class))->getFileName());
if (file_exists($path . '/forms/action.xml'))
{
$form->loadFile($path . '/forms/action.xml');
}
return $workflow;
}
/**
* Get the workflow for a given ID
*
* @param int|null $workflow_id ID of the workflow
*
* @return CMSObject|boolean Object on success, false on failure.
*
* @since 4.0.0
*/
protected function getWorkflow(int $workflow_id = null)
{
$workflow_id = !empty($workflow_id) ? $workflow_id : $this->app->input->getInt('workflow_id');
if (is_array($workflow_id))
{
return false;
}
return $this->app->bootComponent('com_workflow')
->getMVCFactory()
->createModel('Workflow', 'Administrator', ['ignore_request' => true])
->getItem($workflow_id);
}
/**
* Check if the current plugin should execute workflow related activities
*
* @param string $context Context to check
*
* @return boolean
*
* @since 4.0.0
*/
protected function isSupported($context)
{
return false;
}
/**
* Check if the context is listed in the whitelist or in the blacklist and return the result
*
* @param string $context Context to check
*
* @return boolean
*/
protected function checkWhiteAndBlacklist($context)
{
$whitelist = \array_filter((array) $this->params->get('whitelist', []));
$blacklist = \array_filter((array) $this->params->get('blacklist', []));
if (!empty($whitelist))
{
foreach ($whitelist as $allowed)
{
if ($context === $allowed)
{
return true;
}
}
return false;
}
foreach ($blacklist as $forbidden)
{
if ($context === $forbidden)
{
return false;
}
}
return true;
}
/**
* Check if the context is listed in the whitelist or in the blacklist and return the result
*
* @param string $context Context to check
* @param string $functionality The functionality
*
* @return boolean
*/
protected function checkExtensionSupport($context, $functionality)
{
$parts = explode('.', $context);
$component = $this->app->bootComponent($parts[0]);
if (!$component instanceof WorkflowServiceInterface
|| !$component->isWorkflowActive($context)
|| !$component->supportFunctionality($functionality, $context))
{
return false;
}
return true;
}
}
The same content is in 3 releases, Joomla 4.0.0-beta2 to 4.0.0-beta4. See them all, or every version of this file.