- md5
- cbd99a6ad6d9b122369ae7a23d28891a
- sha1
- 03633e8c6beff9f87ab42ba369a7a29bd578a6d7
- sha256
- 9b67fc41b821d8d707692e2f9c56421ae11b8764c5e9b7ef303bcb57e1fbf2da
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
<?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
defined('JPATH_BASE') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormHelper;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Workflow\Workflow;
use Joomla\Utilities\ArrayHelper;
FormHelper::loadFieldClass('list');
/**
* Components Category field.
*
* @since 4.0.0
*/
class TransitionField extends ListField
{
/**
* The form field type.
*
* @var string
* @since 4.0.0
*/
protected $type = 'Transition';
/**
* The component and section separated by ".".
*
* @var string
* @since 4.0.0
*/
protected $extension;
/**
* The workflow stage to use.
*
* @var integer
*/
protected $workflowStage;
/**
* Method to setup the extension
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @since 4.0.0
*/
public function setup(\SimpleXMLElement $element, $value, $group = null)
{
$result = parent::setup($element, $value, $group);
if ($result)
{
$input = Factory::getApplication()->input;
if (strlen($element['extension']))
{
$this->extension = (string) $element['extension'];
}
else
{
$this->extension = $input->getCmd('extension');
}
if (strlen($element['workflow_stage']))
{
$this->workflowStage = (int) $element['workflow_stage'];
}
else
{
$this->workflowStage = $input->getInt('id');
}
}
return $result;
}
/**
* Method to get a list of options for a list input.
*
* @return array An array of HTMLHelper options.
*
* @since 4.0.0
*/
protected function getOptions()
{
// Let's get the id for the current item, either category or content item.
$jinput = Factory::getApplication()->input;
// Initialise variable.
$db = Factory::getDbo();
$extension = $this->extension;
$workflowStage = $this->workflowStage;
$query = $db->getQuery(true)
->select($db->quoteName(['t.id', 't.title', 's.condition'], ['value', 'text', 'condition']))
->from($db->quoteName('#__workflow_transitions', 't'))
->from($db->quoteName('#__workflow_stages', 's'))
->from($db->quoteName('#__workflow_stages', 's2'))
->where($db->quoteName('t.from_stage_id') . ' IN(-1, ' . (int) $workflowStage . ')')
->where($db->quoteName('t.to_stage_id') . ' = ' . $db->quoteName('s.id'))
->where($db->quoteName('t.to_stage_id') . ' != ' . (int) $workflowStage)
->where($db->quoteName('s.workflow_id') . ' = ' . $db->quoteName('s2.workflow_id'))
->where($db->quoteName('s2.id') . ' = ' . (int) $workflowStage)
->where($db->quoteName('t.published') . '= 1')
->where($db->quoteName('s.published') . '= 1')
->order($db->quoteName('t.ordering'));
$items = $db->setQuery($query)->loadObjectList();
if (count($items))
{
$user = Factory::getUser();
$items = array_filter(
$items,
function ($item) use ($user, $extension)
{
return $user->authorise('core.execute.transition', $extension . '.transition.' . $item->value);
}
);
// Sort by transition name
$items = ArrayHelper::sortObjects($items, 'value', 1, true, true);
Factory::getLanguage()->load('com_workflow', JPATH_ADMINISTRATOR);
$workflow = new Workflow(['extension' => $this->extension]);
foreach ($items as $item)
{
$conditionName = $workflow->getConditionName($item->condition);
$item->text .= ' [' . Text::_($conditionName) . ']';
}
}
// Get workflow stage title
$query
->clear()
->select($db->quoteName('title'))
->from($db->quoteName('#__workflow_stages'))
->where($db->quoteName('id') . ' = ' . (int) $workflowStage);
$workflowName = $db->setQuery($query)->loadResult();
$default = [HTMLHelper::_('select.option', '', Text::_($workflowName))];
$options = array_merge(parent::getOptions(), $items);
if (count($options))
{
$default[] = HTMLHelper::_('select.option', '-1', '--------', ['disable' => true]);
}
// Merge with defaults
return array_merge($default, $options);
}
}
The same content is in 2 releases, Joomla 4.0.0-alpha5 to 4.0.0-alpha6. See them all, or every version of this file.