Skip to content

Commit

Permalink
Add context selector for workflow (joomla#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
bembelimen authored and sakiss committed Oct 16, 2020
1 parent 35cb5be commit 4ff9d23
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,24 @@ public function getContexts(): array
return $contexts;
}

/**
* Returns valid contexts
*
* @return array
*
* @since 4.0.0
*/
public function getWorkflowContexts(): array
{
Factory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR);

$contexts = array(
'com_content.article' => Text::_('COM_CONTENT')
);

return $contexts;
}

/**
* Returns the table for the count items functions for the given section.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<form>
<form addfieldprefix="Joomla\Component\Workflow\Administrator\Field">
<fieldset name="group">
<field
name="extension"
type="workflowcontexts"
filtermode="selector"
onchange="this.form.submit();"
/>
</fieldset>
<fields name="filter">
<field
name="search"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_workflow
*
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Component\Workflow\Administrator\Field;

\defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Workflow\WorkflowServiceInterface;
use Joomla\CMS\Form\Field\ListField;

/**
* Fields Contexts
*
* @since 4.0.0
*/
class WorkflowcontextsField extends ListField
{
/**
* Type of the field
*
* @var string
*/
public $type = 'Workflowcontexts';

/**
* Method to get the field input markup for a generic list.
* Use the multiple attribute to enable multiselect.
*
* @return string The field input markup.
*
* @since 4.0.0
*/
protected function getInput()
{
if (count($this->getOptions()) < 2)
{
$this->layout = 'joomla.form.field.hidden';
}

return parent::getInput();
}

/**
* Method to get the field options.
*
* @return array The field option objects.
*
* @since 4.0.0
*/
protected function getOptions()
{
$parts = explode('.', $this->value);

$component = Factory::getApplication()->bootComponent($parts[0]);

if ($component instanceof WorkflowServiceInterface)
{
return $component->getWorkflowContexts();
}

return [];
}
}
22 changes: 22 additions & 0 deletions administrator/components/com_workflow/src/Model/WorkflowsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,28 @@ public function getItems()
return $items;
}

/**
* Get the filter form
*
* @param array $data data
* @param boolean $loadData load current data
*
* @return \JForm|false the JForm object or false
*
* @since 4.0.0
*/
public function getFilterForm($data = array(), $loadData = true)
{
$form = parent::getFilterForm($data, $loadData);

if ($form)
{
$form->setValue('extension', null, $this->getState('filter.extension'));
}

return $form;
}

/**
* Add the number of transitions and states to all workflow items
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<div id="j-main-container" class="j-main-container">
<?php
// Search tools bar
echo LayoutHelper::render('joomla.searchtools.default', array('view' => $this));
echo LayoutHelper::render('joomla.searchtools.default', array('view' => $this, 'options' => array('selectorFieldName' => 'extension')));
?>
<?php if (empty($this->workflows)) : ?>
<div class="alert alert-info">
Expand Down Expand Up @@ -169,7 +169,6 @@
<?php endif; ?>
<input type="hidden" name="task" value="">
<input type="hidden" name="boxchecked" value="0">
<input type="hidden" name="extension" value="<?php echo $extension ?>">
<?php echo HTMLHelper::_('form.token'); ?>
</div>
</div>
Expand Down
9 changes: 9 additions & 0 deletions libraries/src/Workflow/WorkflowServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,13 @@ public static function getConditions(string $extension): array;
* @since 4.0.0
*/
public function getWorkflowTableBySection(?string $section = null): string;

/**
* Returns valid contexts.
*
* @return array
*
* @since 4.0.0
*/
public function getWorkflowContexts(): array;
}

0 comments on commit 4ff9d23

Please sign in to comment.