- md5
- a37c56e8d6a739a31df679b39e6a2ba5
- sha1
- da60249ed68550748ef5bd9e4ff6645ebe400b4a
- sha256
- 2af800916753758f1087e7405936eea2bbdac119c969ae2d0b661217716312dd
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 funcationality
*
* @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;
}
}
No other release has this exact content. See every version of this file.