Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -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);
40 changes: 22 additions & 18 deletions administrator/components/com_content/Model/ArticleModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -931,7 +931,7 @@ public function save($data)
}
}

$workflow = new Workflow(['extension' => 'com_content']);
$workflow = new Workflow('com_content');

if (parent::save($data))
{
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
41 changes: 32 additions & 9 deletions administrator/components/com_workflow/Model/TransitionModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');

Expand All @@ -95,6 +96,8 @@ protected function canEditState($record)
return false;
}

$user = $app->getIdentity();

// Check for existing workflow.
if (!empty($record->id))
{
Expand Down Expand Up @@ -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
*/
Expand All @@ -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');
Expand All @@ -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;
}
Expand Down Expand Up @@ -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.
Expand All @@ -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);
}
}
10 changes: 9 additions & 1 deletion administrator/components/com_workflow/Table/TransitionTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
*/
Expand Down
39 changes: 17 additions & 22 deletions administrator/components/com_workflow/View/Transition/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,47 +37,39 @@ class HtmlView extends BaseHtmlView
/**
* From object to generate fields
*
* @var \JForm
* @var Form
* @since 4.0.0
*/
protected $form;

/**
* 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;

/**
* Use core ui in different layouts
*
* @var Integer
* @var integer
* @since 4.0.0
*/
protected $useCoreUI = true;
Expand All @@ -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');
Expand All @@ -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);
Expand All @@ -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);

Expand Down
37 changes: 16 additions & 21 deletions administrator/components/com_workflow/forms/transition.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,22 @@
rows="3"
cols="60"
/>
<field
name="published"
type="list"
label="COM_WORKFLOW_PUBLISHED_LABEL"
required="true"
class="custom-select-color-state"
default="1"
>
<option value="1">JENABLED</option>
<option value="0">JDISABLED</option>
<option value="-2">JTRASHED</option>
</field>

<fieldset name="options" label="COM_WORKFLOW_OPTIONS_LABEL">

<fields name="options">

</fields>

</fieldset>

<field
name="workflow_id"
type="hidden"
/>
<field
name="published"
type="list"
label="COM_WORKFLOW_PUBLISHED_LABEL"
required="true"
class="custom-select-color-state"
default="1"
>
<option value="1">JENABLED</option>
<option value="0">JDISABLED</option>
<option value="-2">JTRASHED</option>
</field>
<field
name="asset_id"
type="hidden"
Expand Down
Loading