diff --git a/administrator/components/com_admin/sql/updates/mysql/4.0.0-2019-11-22.sql b/administrator/components/com_admin/sql/updates/mysql/4.0.0-2019-11-22.sql
new file mode 100644
index 0000000000000..c9b520d580ab7
--- /dev/null
+++ b/administrator/components/com_admin/sql/updates/mysql/4.0.0-2019-11-22.sql
@@ -0,0 +1,2 @@
+INSERT INTO `#__extensions` (`name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `checked_out`, `checked_out_time`, `ordering`, `state`) VALUES
+('plg_workflow_publishing', 'plugin', 'publishing', 'workflow', 0, 1, 1, 0, '', '{}', 0, NULL, 0, 0);
diff --git a/administrator/components/com_admin/sql/updates/postgresql/4.0.0-2019-11-22.sql b/administrator/components/com_admin/sql/updates/postgresql/4.0.0-2019-11-22.sql
new file mode 100644
index 0000000000000..276e475a6826a
--- /dev/null
+++ b/administrator/components/com_admin/sql/updates/postgresql/4.0.0-2019-11-22.sql
@@ -0,0 +1,2 @@
+INSERT INTO "#__extensions" ("name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "manifest_cache", "params", "checked_out", "checked_out_time", "ordering", "state") VALUES
+('plg_workflow_publishing', 'plugin', 'publishing', 'workflow', 0, 1, 1, 0, '', '{}', 0, NULL, 0, 0);
diff --git a/administrator/components/com_content/Model/ArticleModel.php b/administrator/components/com_content/Model/ArticleModel.php
index f0892acb8bf06..5589f91e72459 100644
--- a/administrator/components/com_content/Model/ArticleModel.php
+++ b/administrator/components/com_content/Model/ArticleModel.php
@@ -149,7 +149,7 @@ protected function batchWorkflowStage($value, $pks, $contexts)
return false;
}
- $workflow = new Workflow(['extension' => 'com_content']);
+ $workflow = new Workflow('com_content');
// Update content state value and workflow associations
return $workflow->updateAssociations($pks, $value);
@@ -562,7 +562,7 @@ public function getForm($data = array(), $loadData = true)
if ($table->load(array('id' => $id)))
{
- $workflow = new Workflow(['extension' => 'com_content']);
+ $workflow = new Workflow('com_content');
// Transition field
$assoc = $workflow->getAssociation($table->id);
@@ -931,7 +931,7 @@ public function save($data)
}
}
- $workflow = new Workflow(['extension' => 'com_content']);
+ $workflow = new Workflow('com_content');
if (parent::save($data))
{
@@ -1238,7 +1238,7 @@ public function delete(&$pks)
$db->setQuery($query);
$db->execute();
- $workflow = new Workflow(['extension' => 'com_content']);
+ $workflow = new Workflow('com_content');
$workflow->deleteAssociation($pks);
}
@@ -1350,18 +1350,31 @@ protected function getWorkflowByCategory($catId)
/**
* Runs transition for item.
*
- * @param integer $pk Id of article
- * @param integer $transition_id Id of transition
+ * @param integer $pk Id of article
+ * @param integer $transitionId Id of transition
*
* @return boolean
*
* @since 4.0.0
*/
- public function runTransition($pk, $transition_id)
+ public function runTransition($pk, $transitionId)
{
- $workflow = new Workflow(['extension' => 'com_content']);
+ $workflow = new Workflow('com_content');
- $runTransaction = $workflow->executeTransition($pk, $transition_id);
+ // Include the plugins for the change of state event.
+ // TODO: Is this the right place to import workflow plugins - potentially better in the executeTransition method
+ PluginHelper::importPlugin('workflow');
+ PluginHelper::importPlugin($this->events_map['change_state']);
+
+ // B/C state change trigger for UCM
+ $context = $this->option . '.' . $this->name;
+
+ $publishingOptions = [
+ 'context' => $context,
+ 'changeStateEvent' => $this->event_change_state,
+ ];
+
+ $runTransaction = $workflow->executeTransition($pk, $transitionId, ['publishing' => $publishingOptions]);
if (!$runTransaction)
{
@@ -1370,15 +1383,6 @@ public function runTransition($pk, $transition_id)
return false;
}
- // B/C state change trigger for UCM
- $context = $this->option . '.' . $this->name;
-
- // Include the plugins for the change of stage event.
- PluginHelper::importPlugin($this->events_map['change_state']);
-
- // Trigger the change stage event.
- Factory::getApplication()->triggerEvent($this->event_change_state, [$context, [$pk], $workflow->getConditionForTransition($transition_id)]);
-
return true;
}
}
diff --git a/administrator/components/com_content/Model/ArticlesModel.php b/administrator/components/com_content/Model/ArticlesModel.php
index 8121aacb4af9c..1724a289ebca1 100644
--- a/administrator/components/com_content/Model/ArticlesModel.php
+++ b/administrator/components/com_content/Model/ArticlesModel.php
@@ -568,7 +568,7 @@ public function getTransitions()
$transitions = $db->setQuery($query)->loadAssocList();
- $workflow = new Workflow(['extension' => 'com_content']);
+ $workflow = new Workflow('com_content');
foreach ($transitions as $key => $transition)
{
diff --git a/administrator/components/com_workflow/Model/TransitionModel.php b/administrator/components/com_workflow/Model/TransitionModel.php
index 011f5fdbebabc..e9719249d33b9 100644
--- a/administrator/components/com_workflow/Model/TransitionModel.php
+++ b/administrator/components/com_workflow/Model/TransitionModel.php
@@ -14,6 +14,8 @@
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\AdminModel;
+use Joomla\CMS\Object\CMSObject;
+use Joomla\Registry\Registry;
use Joomla\String\StringHelper;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Plugin\PluginHelper;
@@ -82,7 +84,6 @@ protected function canDelete($record)
*/
protected function canEditState($record)
{
- $user = Factory::getUser();
$app = Factory::getApplication();
$extension = $app->getUserStateFromRequest('com_workflow.transition.filter.extension', 'extension', null, 'cmd');
@@ -95,6 +96,8 @@ protected function canEditState($record)
return false;
}
+ $user = $app->getIdentity();
+
// Check for existing workflow.
if (!empty($record->id))
{
@@ -210,7 +213,7 @@ protected function generateNewTitle($category_id, $alias, $title)
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
*
- * @return \JForm|boolean A JForm object on success, false on failure
+ * @return Form|boolean A JForm object on success, false on failure
*
* @since 4.0.0
*/
@@ -233,10 +236,10 @@ public function getForm($data = array(), $loadData = true)
if ($loadData)
{
- $data = (object) $this->loadFormData();
+ $data = $this->loadFormData();
}
- if (!$this->canEditState($data))
+ if (!$this->canEditState((object) $data))
{
// Disable fields for display.
$form->setFieldAttribute('published', 'disabled', 'true');
@@ -254,6 +257,7 @@ public function getForm($data = array(), $loadData = true)
$form->setFieldAttribute('from_stage_id', 'sql_where', $where);
$form->setFieldAttribute('to_stage_id', 'sql_where', $where);
+ $form->setValue('workflow_id', '', $workflow_id);
return $form;
}
@@ -282,7 +286,29 @@ protected function loadFormData()
}
/**
- * Method to allow derived classes to preprocess the form.
+ * Method to get a single record.
+ *
+ * @param integer $pk The id of the primary key.
+ *
+ * @return CMSObject|boolean Object on success, false on failure.
+ *
+ * @since 1.6
+ */
+ public function getItem($pk = null)
+ {
+ $item = parent::getItem($pk);
+
+ if ($item && property_exists($item, 'options'))
+ {
+ $registry = new Registry($item->options);
+ $item->options = $registry->toArray();
+ }
+
+ return $item;
+ }
+
+ /**
+ * Method to allow derived classes to preprocess the form. Overridden to specify the plugin group.
*
* @param Form $form A Form object.
* @param mixed $data The data expected for the form.
@@ -294,11 +320,8 @@ protected function loadFormData()
* @since 4.0.0
* @throws \Exception if there is an error in the form event.
*/
- protected function preprocessForm(Form $form, $data, $group = 'content')
+ protected function preprocessForm(Form $form, $data, $group = 'workflow')
{
- // Import the appropriate plugin group.
- PluginHelper::importPlugin('workflow');
-
parent::preprocessForm($form, $data, $group);
}
}
diff --git a/administrator/components/com_workflow/Table/TransitionTable.php b/administrator/components/com_workflow/Table/TransitionTable.php
index 43f2f1d238351..280abd05e5da6 100644
--- a/administrator/components/com_workflow/Table/TransitionTable.php
+++ b/administrator/components/com_workflow/Table/TransitionTable.php
@@ -22,6 +22,14 @@
*/
class TransitionTable extends Table
{
+ /**
+ * An array of key names to be json encoded in the bind function
+ *
+ * @var array
+ * @since __DEPLOY_VERSION__
+ */
+ protected $_jsonEncode = ['options'];
+
/**
* Indicates that columns fully support the NULL value in the database
*
@@ -33,7 +41,7 @@ class TransitionTable extends Table
/**
* Constructor
*
- * @param \JDatabaseDriver $db Database connector object
+ * @param DatabaseDriver $db Database connector object
*
* @since 4.0.0
*/
diff --git a/administrator/components/com_workflow/View/Transition/HtmlView.php b/administrator/components/com_workflow/View/Transition/HtmlView.php
index a6a286a7dcfca..1dd13e7dd3bdd 100644
--- a/administrator/components/com_workflow/View/Transition/HtmlView.php
+++ b/administrator/components/com_workflow/View/Transition/HtmlView.php
@@ -10,7 +10,9 @@
defined('_JEXEC') or die;
+use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Factory;
+use Joomla\CMS\Form\Form;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
@@ -35,7 +37,7 @@ class HtmlView extends BaseHtmlView
/**
* From object to generate fields
*
- * @var \JForm
+ * @var Form
* @since 4.0.0
*/
protected $form;
@@ -43,31 +45,23 @@ class HtmlView extends BaseHtmlView
/**
* Items array
*
- * @var object
+ * @var object
* @since 4.0.0
*/
protected $item;
/**
- * That is object of Application
+ * The extension that the workflow will be used on
*
- * @var CMSApplication
+ * @var string
* @since 4.0.0
*/
- protected $app;
-
- /**
- * The application input object.
- *
- * @var Input
- * @since 4.0.0
- */
- protected $input;
+ protected $extension;
/**
* The ID of current workflow
*
- * @var Integer
+ * @var integer
* @since 4.0.0
*/
protected $workflowID;
@@ -75,7 +69,7 @@ class HtmlView extends BaseHtmlView
/**
* Use core ui in different layouts
*
- * @var Integer
+ * @var integer
* @since 4.0.0
*/
protected $useCoreUI = true;
@@ -97,8 +91,7 @@ public function display($tpl = null)
throw new GenericDataException(implode("\n", $errors), 500);
}
- $this->app = Factory::getApplication();
- $this->input = $this->app->input;
+ $app = Factory::getApplication();
// Get the Data
$this->state = $this->get('State');
@@ -107,10 +100,10 @@ public function display($tpl = null)
$this->extension = $this->state->get('filter.extension');
// Get the ID of workflow
- $this->workflowID = $this->input->getCmd("workflow_id");
+ $this->workflowID = $app->input->getCmd("workflow_id");
// Set the toolbar
- $this->addToolBar();
+ $this->addToolBar($app);
// Display the template
parent::display($tpl);
@@ -119,15 +112,17 @@ public function display($tpl = null)
/**
* Add the page title and toolbar.
*
+ * @param CMSApplicationInterface $app The Application object
+ *
* @return void
*
* @since 4.0.0
*/
- protected function addToolbar()
+ protected function addToolbar($app)
{
- Factory::getApplication()->input->set('hidemainmenu', true);
+ $app->input->set('hidemainmenu', true);
- $user = Factory::getUser();
+ $user = $app->getIdentity();
$userId = $user->id;
$isNew = empty($this->item->id);
diff --git a/administrator/components/com_workflow/forms/transition.xml b/administrator/components/com_workflow/forms/transition.xml
index 38e3ccf404465..f291f1523b2dd 100644
--- a/administrator/components/com_workflow/forms/transition.xml
+++ b/administrator/components/com_workflow/forms/transition.xml
@@ -45,27 +45,22 @@
rows="3"
cols="60"
/>
-
-
-
-
-
-
-
-
+
+
+
+
+
+
input->get('layout') === 'modal';
+$input = Factory::getApplication()->input;
+$isModal = $input->get('layout') === 'modal';
$layout = $isModal ? 'modal' : 'edit';
-$tmpl = $isModal || $this->input->get('tmpl', '', 'cmd') === 'component' ? '&tmpl=component' : '';
+$tmpl = $isModal || $input->get('tmpl', '', 'cmd') === 'component' ? '&tmpl=component' : '';
?>
-
diff --git a/installation/sql/mysql/joomla.sql b/installation/sql/mysql/joomla.sql
index 54c0fb4c05932..0a2b3dd4edf14 100644
--- a/installation/sql/mysql/joomla.sql
+++ b/installation/sql/mysql/joomla.sql
@@ -720,6 +720,7 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`,
(0, 'plg_media-action_crop', 'plugin', 'crop', 'media-action', 0, 1, 1, 0, '', '{}', 0, NULL, 0, 0),
(0, 'plg_media-action_resize', 'plugin', 'resize', 'media-action', 0, 1, 1, 0, '', '{}', 0, NULL, 0, 0),
(0, 'plg_media-action_rotate', 'plugin', 'rotate', 'media-action', 0, 1, 1, 0, '', '{}', 0, NULL, 0, 0),
+(0, 'plg_workflow_publishing', 'plugin', 'publishing', 'workflow', 0, 1, 1, 0, '', '{}', 0, NULL, 0, 0),
(0, 'atum', 'template', 'atum', '', 1, 1, 1, 0, '', '', 0, NULL, 0, 0),
(0, 'cassiopeia', 'template', 'cassiopeia', '', 0, 1, 1, 0, '', '{"logoFile":"","fluidContainer":"0","sidebarLeftWidth":"3","sidebarRightWidth":"3"}', 0, NULL, 0, 0),
(0, 'plg_fields_subfields', 'plugin', 'subfields', 'fields', 0, 1, 1, 0, '', '', 0, NULL, 0, 0),
diff --git a/installation/sql/postgresql/joomla.sql b/installation/sql/postgresql/joomla.sql
index e23b66256d874..c29c58e04236c 100644
--- a/installation/sql/postgresql/joomla.sql
+++ b/installation/sql/postgresql/joomla.sql
@@ -731,6 +731,7 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder",
(0, 'plg_media-action_crop', 'plugin', 'crop', 'media-action', 0, 1, 1, 0, '', '{}', 0, NULL, 0, 0),
(0, 'plg_media-action_resize', 'plugin', 'resize', 'media-action', 0, 1, 1, 0, '', '{}', 0, NULL, 0, 0),
(0, 'plg_media-action_rotate', 'plugin', 'rotate', 'media-action', 0, 1, 1, 0, '', '{}', 0, NULL, 0, 0),
+(0, 'plg_workflow_publishing', 'plugin', 'publishing', 'workflow', 0, 1, 1, 0, '', '{}', 0, NULL, 0, 0),
(0, 'atum', 'template', 'atum', '', 1, 1, 1, 0, '', '', 0, NULL, 0, 0),
(0, 'cassiopeia', 'template', 'cassiopeia', '', 0, 1, 1, 0, '', '{"logoFile":"","fluidContainer":"0","sidebarLeftWidth":"3","sidebarRightWidth":"3"}', 0, NULL, 0, 0),
(0, 'plg_fields_subfields', 'plugin', 'subfields', 'fields', 0, 1, 1, 0, '', '', 0, NULL, 0, 0),
diff --git a/libraries/src/MVC/Controller/AdminController.php b/libraries/src/MVC/Controller/AdminController.php
index 316e5c02fb5be..f6bed904a3027 100644
--- a/libraries/src/MVC/Controller/AdminController.php
+++ b/libraries/src/MVC/Controller/AdminController.php
@@ -425,7 +425,7 @@ public function saveOrderAjax()
/**
* Method to run Transition by id of item.
*
- * @return boolean Indicates whether the transition was succesful.
+ * @return boolean Indicates whether the transition was successful.
*
* @since 4.0.0
*/
diff --git a/libraries/src/Workflow/Workflow.php b/libraries/src/Workflow/Workflow.php
index 9d0cc9622aeef..2aa1ea92fd170 100644
--- a/libraries/src/Workflow/Workflow.php
+++ b/libraries/src/Workflow/Workflow.php
@@ -36,13 +36,6 @@ class Workflow
*/
protected $extension = null;
- /**
- * Workflow options
- *
- * @var array
- */
- protected $options = [];
-
/**
* @var \Joomla\Database\DatabaseDriver
*/
@@ -83,21 +76,14 @@ class Workflow
/**
* Class constructor
*
- * @param array $options Array of options
+ * @param string $extension The extension the workflow is operating on (including optional
+ * dot separated extension)
*
* @since 4.0.0
*/
- public function __construct($options)
+ public function __construct($extension)
{
- // Required options
- $this->extension = $options['extension'];
-
- // Default some optional options
- $this->options['access'] = 'true';
- $this->options['published'] = 1;
- $this->options['countItems'] = 0;
-
- $this->setOptions($options);
+ $this->extension = $extension;
}
/**
@@ -115,7 +101,7 @@ public function getConditionName($value)
if ($component instanceof WorkflowServiceInterface)
{
- $conditions = $component->getConditions($this->extension);
+ $conditions = $component->getConditions();
}
else
{
@@ -147,12 +133,13 @@ protected function getComponent()
/**
* Executes a transition to change the current state in the association table
*
- * @param array|int $pks The item IDs, which should use the transition
- * @param int $transition_id The transition which should be executed
+ * @param array|int $pks The item IDs, which should use the transition
+ * @param int $transitionId The transition which should be executed
+ * @param array $options An array of options to pass into plugin events
*
* @return boolean
*/
- public function executeTransition($pks, $transition_id)
+ public function executeTransition($pks, $transitionId, $options = [])
{
if (!\is_array($pks))
{
@@ -175,19 +162,15 @@ public function executeTransition($pks, $transition_id)
't.id',
't.to_stage_id',
't.from_stage_id',
- 's.condition',
+ 't.options',
]
);
$query->select($select)
->from($db->quoteName('#__workflow_transitions', 't'))
->leftJoin($db->quoteName('#__workflow_stages', 's') . ' ON ' . $db->quoteName('s.id') . ' = ' . $db->quoteName('t.to_stage_id'))
- ->where($db->quoteName('t.id') . ' = ' . (int) $transition_id);
-
- if (!empty($this->options['published']))
- {
- $query->where($db->quoteName('t.published') . ' = 1');
- }
+ ->where($db->quoteName('t.id') . ' = ' . (int) $transitionId)
+ ->where($db->quoteName('t.published') . ' = 1');
$transition = $db->setQuery($query)->loadObject();
@@ -211,6 +194,7 @@ public function executeTransition($pks, $transition_id)
'extension' => $this->extension,
'user' => $app->getIdentity(),
'transition' => $transition,
+ 'options' => $options,
]
);
@@ -230,6 +214,7 @@ public function executeTransition($pks, $transition_id)
'extension' => $this->extension,
'user' => $app->getIdentity(),
'transition' => $transition,
+ 'options' => $options,
]
);
}
@@ -331,7 +316,7 @@ public function updateAssociations($pks, $state)
/**
* Removes associations form the workflow_associations table
*
- * @param int $pks ID of content
+ * @param array $pks ID of content
*
* @return boolean
*
@@ -390,31 +375,4 @@ public function getAssociation($item_id)
return $db->setQuery($query)->loadObject();
}
-
- /**
- * Allows to set some optional options, eg. if the access level should be considered.
- *
- * @param array $options The new options
- *
- * @return void
- *
- * @since 4.0.0
- */
- public function setOptions(array $options)
- {
- if (isset($options['access']))
- {
- $this->options['access'] = $options['access'];
- }
-
- if (isset($options['published']))
- {
- $this->options['published'] = $options['published'];
- }
-
- if (isset($options['countItems']))
- {
- $this->options['countItems'] = $options['countItems'];
- }
- }
}
diff --git a/libraries/src/Workflow/WorkflowServiceInterface.php b/libraries/src/Workflow/WorkflowServiceInterface.php
index c6497cf2385b1..6d08ffae77073 100644
--- a/libraries/src/Workflow/WorkflowServiceInterface.php
+++ b/libraries/src/Workflow/WorkflowServiceInterface.php
@@ -44,13 +44,13 @@ public static function updateContentState($pks, $condition): bool;
/**
* Returns an array of possible conditions for the component.
*
- * @param string $extension Full extension string
+ * @param string $section Optional section for the component
*
* @return array
*
* @since 4.0.0
*/
- public static function getConditions($extension): array;
+ public static function getConditions($section = null): array;
/**
* Returns a table name for the state association
diff --git a/libraries/src/Workflow/WorkflowServiceTrait.php b/libraries/src/Workflow/WorkflowServiceTrait.php
index c03c1e70f822d..3647fe22aaeb8 100644
--- a/libraries/src/Workflow/WorkflowServiceTrait.php
+++ b/libraries/src/Workflow/WorkflowServiceTrait.php
@@ -20,13 +20,13 @@ trait WorkflowServiceTrait
/**
* Returns an array of possible conditions for the component.
*
- * @param string $extension The component and section separated by ".".
+ * @param string $section Optional section for the component
*
* @return array
*
* @since 4.0.0
*/
- public static function getConditions($extension): array
+ public static function getConditions($section = null): array
{
return \defined('self::CONDITION_NAMES') ? self::CONDITION_NAMES : Workflow::CONDITION_NAMES;
}
diff --git a/plugins/content/joomla/joomla.php b/plugins/content/joomla/joomla.php
index 990ab3040411c..0a232d2ca4e80 100644
--- a/plugins/content/joomla/joomla.php
+++ b/plugins/content/joomla/joomla.php
@@ -648,7 +648,7 @@ public function onContentChangeState($context, $pks, $value)
$article = new ArticleTable($db);
- $workflow = new Workflow(['extension' => 'com_content']);
+ $workflow = new Workflow('com_content');
foreach ($pks as $pk)
{
@@ -703,9 +703,10 @@ function ($item) use ($user)
'message' => sprintf($lang->_('PLG_CONTENT_JOOMLA_ON_STAGE_CHANGE_MSG'), $user->name, $article->title),
);
- $model_message = $this->app->bootComponent('com_messages')
+ /** @var \Joomla\Component\Messages\Administrator\Model\MessageModel $modelMessage */
+ $modelMessage = $this->app->bootComponent('com_messages')
->getMVCFactory()->createModel('Message', 'Administrator');
- $model_message->save($message);
+ $modelMessage->save($message);
}
}
}
diff --git a/plugins/workflow/publishing/field/publishing.php b/plugins/workflow/publishing/field/publishing.php
new file mode 100644
index 0000000000000..47a2ddec6f203
--- /dev/null
+++ b/plugins/workflow/publishing/field/publishing.php
@@ -0,0 +1,64 @@
+input->getCmd('extension');
+ $extensionInterface = $app->bootComponent($extension);
+
+ $publishList = parent::getOptions();
+
+ if ($extensionInterface instanceof WorkflowServiceInterface)
+ {
+ // TODO: Concept of sections
+ $conditions = $extensionInterface->getConditions();
+
+ foreach ($conditions as $value => $text)
+ {
+ $conditions[$value] = Text::_($text);
+ }
+
+ return array_merge($publishList, $conditions);
+ }
+
+ return $publishList;
+ }
+}
diff --git a/plugins/workflow/publishing/forms/publishing.xml b/plugins/workflow/publishing/forms/publishing.xml
index 55d5193b0b2fb..7ecfa5c66bbf8 100644
--- a/plugins/workflow/publishing/forms/publishing.xml
+++ b/plugins/workflow/publishing/forms/publishing.xml
@@ -1,20 +1,17 @@
diff --git a/plugins/workflow/publishing/publishing.php b/plugins/workflow/publishing/publishing.php
index a98d2bcdb2c16..ab4ae6531cf25 100644
--- a/plugins/workflow/publishing/publishing.php
+++ b/plugins/workflow/publishing/publishing.php
@@ -9,38 +9,121 @@
defined('_JEXEC') or die;
+use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Form\Form;
+use Joomla\CMS\User\User;
+use Joomla\CMS\Workflow\WorkflowServiceInterface;
/**
* Publishing handling for workflow items
*
- * @since 4.0.0
+ * @since __DEPLOY_VERSION__
*/
class PlgWorkflowPublishing extends CMSPlugin
{
+ /**
+ * The Application Object
+ *
+ * @var CMSApplication
+ * @since __DEPLOY_VERSION__
+ */
+ protected $app;
+
/**
* Load the language file on instantiation.
*
* @var boolean
- * @since 4.0.0
+ * @since __DEPLOY_VERSION__
*/
protected $autoloadLanguage = true;
+ /**
+ * Constructor
+ *
+ * @param object &$subject The object to observe
+ * @param array $config An array that holds the plugin configuration
+ *
+ * @since 1.5
+ */
+ public function __construct(& $subject, $config)
+ {
+ parent::__construct($subject, $config);
+
+ Form::addFieldPath(__DIR__ . '/field');
+ }
+
/**
* Add additional fields to the supported forms
*
- * @param Form $form The form to be altered.
+ * @param Form $form The form to be altered.
* @param mixed $data The associated data for the form.
*
* @return boolean
*
- * @since 4.0.0
+ * @since __DEPLOY_VERSION__
*/
public function onContentPrepareForm(Form $form, $data)
+ {
+ // Check we are manipulating the workflow form.
+ if ($form->getName() === 'com_workflow.transition')
+ {
+ $this->loadPublishingFormForTransitionView($form);
+ }
+
+ return true;
+ }
+
+ /**
+ * Adds the publishing field to the transition view
+ *
+ * @param Form $form The form to be altered.
+ *
+ * @return void
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ private function loadPublishingFormForTransitionView($form)
{
Form::addFormPath(__DIR__ . '/forms');
$form->loadFile('publishing');
}
+
+ /**
+ * Updates the content state of the content item after a workflow is transitioned.
+ *
+ * @param integer[] $pks The primary keys.
+ * @param string $extension The extension being altered.
+ * @param User $user The user making the transition.
+ * @param object $transition The extension being altered.
+ * @param \stdClass $options The options for the plugin event.
+ *
+ * @return void
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function onWorkflowAfterTransition($pks, $extension, $user, $transition, $options)
+ {
+ $extensionOptions = json_decode($transition->options, true);
+
+ if (isset($extensionOptions['publishing']))
+ {
+ $extensionInterface = $this->app->bootComponent($extension);
+
+ if ($extensionInterface instanceof WorkflowServiceInterface)
+ {
+ $extensionInterface->updateContentState($pks, $extensionOptions['publishing']);
+
+ if (isset($options['publishing']['changeStateEvent']))
+ {
+ // Trigger the change stage event.
+ $this->app->triggerEvent(
+ $options['publishing']['changeStateEvent'],
+ [$options['publishing']['context'], $pks, $extensionOptions['publishing']]
+ );
+ }
+ }
+ }
+ }
}
diff --git a/plugins/workflow/publishing/publishing.xml b/plugins/workflow/publishing/publishing.xml
index 2f2c820cfec30..714aeb5f8683d 100644
--- a/plugins/workflow/publishing/publishing.xml
+++ b/plugins/workflow/publishing/publishing.xml
@@ -11,6 +11,8 @@
PLG_WORKFLOW_PUBLISHING_XML_DESCRIPTION
publishing.php
+ forms
+ field
language/en-GB/en-GB.plg_workflow_publishing.ini