Skip to content

Commit

Permalink
TransitionsField extends from Groupedlist rather than List (#379)
Browse files Browse the repository at this point in the history
* Update TransitionField.php

Extend Groupedlist rather than List

* Update TransitionField.php

Removed spaces

* Update TransitionField.php

Test if items are present before creating a group
  • Loading branch information
obuisard committed Dec 12, 2022
1 parent 94791af commit 73aa1de
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions libraries/src/Form/Field/TransitionField.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @since 4.0.0
*/
class TransitionField extends ListField
class TransitionField extends GroupedlistField
{
/**
* The form field type.
Expand Down Expand Up @@ -91,7 +91,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null)
*
* @since 4.0.0
*/
protected function getOptions()
protected function getGroups()
{
// Let's get the id for the current item, either category or content item.
$jinput = Factory::getApplication()->getInput();
Expand Down Expand Up @@ -161,17 +161,20 @@ function ($item) use ($user, $component) {

$workflowName = $db->setQuery($query)->loadResult();

$default = [
HTMLHelper::_('select.option', '', Text::_($workflowName))];
$default = [[
HTMLHelper::_('select.option', '', Text::_($workflowName))]];

$options = array_merge(parent::getOptions(), $items);
$groups = parent::getGroups();

if (\count($options)) {
$default[] = HTMLHelper::_('select.option', '-1', '--------', ['disable' => true]);
$default[] = HTMLHelper::_('select.option', '<OPTGROUP>', Text::_('COM_CONTENT_RUN_TRANSITION'));
if (\count($items)) {
$groups[Text::_('COM_CONTENT_RUN_TRANSITION')] = $items;
}

if (\count($groups)) {
$default[][] = HTMLHelper::_('select.option', '-1', '--------', ['disable' => true]);
}

// Merge with defaults
return array_merge($default, $options, [HTMLHelper::_('select.option', '</OPTGROUP>')]);
return array_merge($default, $groups);
}
}

0 comments on commit 73aa1de

Please sign in to comment.