diff --git a/src/Element/WorkflowTransitionElement.php b/src/Element/WorkflowTransitionElement.php index 5195b8ea13e5a5f089b9a158e31e38627cbd9df7..254a09621aaf21f1bf440e26c4044023d8056614 100644 --- a/src/Element/WorkflowTransitionElement.php +++ b/src/Element/WorkflowTransitionElement.php @@ -166,7 +166,7 @@ class WorkflowTransitionElement extends FormElement { if ($transition->isScheduled() || $transition->isExecuted() || !$show_widget) { $from_sid = $element[$attribute_name][$attribute_key]['#default_value'][0]; $widget = workflow_state_formatter($entity, $field_name, $from_sid); - // @todo $widget['#label_display'] = 'before'; + $widget['#label_display'] = 'before'; // 'above', 'hidden'. $widget['#access'] = TRUE; } $element[$attribute_name] = $widget; diff --git a/workflow.field.inc b/workflow.field.inc index 43e5df4d688702dbe2c7f437f499f19b207478e9..1b2e66a250eb0830eec6a761234e78c8c21296ba 100644 --- a/workflow.field.inc +++ b/workflow.field.inc @@ -52,14 +52,14 @@ function workflow_field_widget_info_alter(&$info) { * @return array * Form element, resembling the formatter of List module. * If state 0 is given, return an empty form element. + * It may be needed to add the following after calling this function: + * $widget['#label_display'] = 'before'; // 'above', 'hidden'. */ -function workflow_state_formatter(EntityInterface $entity, $field_name, $current_sid = '') { - $element = []; - if (!$current_sid) { - $current_sid = workflow_node_current_state($entity, $field_name); - } +function workflow_state_formatter(EntityInterface $entity, $field_name, $current_sid = NULL) { + $element = []; + $current_sid ??= workflow_node_current_state($entity, $field_name); // Clone the entity and restore old value, in case you want to show an // executed transition. if ($entity->{$field_name}->value != $current_sid) { @@ -73,6 +73,8 @@ function workflow_state_formatter(EntityInterface $entity, $field_name, $current // $list_display = $instance['display']['default']; . $list_display['type'] = 'list_default'; $element = $entity->{$field_name}->view($list_display); + // Remove label_display to let caller determine it. + unset($element['#label_display']); // If user creates a node, and only 1 option is available, the formatter // is shown with key, not value, because creation state does not count.