Skip to content
Snippets Groups Projects
Commit b3b72fc9 authored by John Voskuilen's avatar John Voskuilen
Browse files

Issue #3510613: Fix WorkflowState->label() in workflow_state_allowed_values()

parent 066e6622
No related branches found
No related tags found
No related merge requests found
Pipeline #438551 passed with warnings
......@@ -157,7 +157,7 @@ class WorkflowState extends ConfigEntityBase implements WorkflowStateInterface {
/**
* {@inheritdoc}
*
* Is used in workflow_allowed_state_names().
* Calls parent::label() and is used in workflow_allowed_state_names().
*/
public function __toString() {
$label = $this->t('@label', ['@label' => $this->label()])->__toString();
......
......@@ -318,23 +318,41 @@ function workflow_allowed_workflow_state_names($wid = '', $grouped = FALSE) {
*/
function workflow_state_allowed_values(FieldStorageDefinitionInterface $field_storage_definition, ?FieldableEntityInterface $entity = NULL, &$cacheable = TRUE) {
// State values cannot be cached since 'to_sid' and 'from_sid' have
// different options and on the Workflow History page,
// a normal widget is displayed, too.
// Also, cache is not per wid, so not possible for multiple wid systems.
// Note: $cacheable is a reference.
$cacheable = FALSE;
switch (TRUE) {
case $entity instanceof WorkflowTransitionInterface && $entity->isExecuted():
case $entity instanceof WorkflowTransitionInterface:
/** @var \Drupal\workflow\Entity\WorkflowTransitionInterface $entity */
$field_name = $field_storage_definition->getName();
$state = match ($field_name) {
'from_sid' => $entity->getFromState(),
'to_sid' => $entity->getToState(),
};
switch (TRUE) {
case $entity->isExecuted():
/** @var \Drupal\workflow\Entity\WorkflowTransitionInterface $entity */
// We are on the Workflow History page/view
// and are editing an existing/executed/not-scheduled transition.
// Only the comments may be changed!
// (Or any other Views display displaying State names)
// or are editing an existing/executed/not-scheduled transition,
// where only the comments may be changed!
// The states may not be changed anymore.
$to_state = $entity->getToState();
$allowed_options = [$to_state->id() => $to_state->label()];
$allowed_options = [$state->id() => $state->label()];
break;
case $entity instanceof WorkflowTransitionInterface:
/** @var \Drupal\workflow\Entity\WorkflowTransitionInterface $entity */
$from_state = $entity->getFromState();
$field_name = $field_storage_definition->getName();
case $field_name == 'from_sid':
$allowed_options = [$state->id() => $state->label()];
break;
case $field_name == 'to_sid':
$user = workflow_current_user();
$allowed_options = $from_state->getOptions($entity, $field_name, $user);
$allowed_options = $state->getOptions($entity, $field_name, $user);
break;
}
break;
case (!$entity):
......@@ -347,6 +365,7 @@ function workflow_state_allowed_values(FieldStorageDefinitionInterface $field_st
$allowed_options = [];
break;
}
return $allowed_options;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment