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

Issue #3513418 by dcoppel, arunsahijpal, spiderman: WidgetBase::errorElement()...

Issue #3513418 by dcoppel, arunsahijpal, spiderman: WidgetBase::errorElement() upon new entity or multiple_value textfield - avoid recursion
parent b82e6149
No related branches found
Tags
No related merge requests found
Pipeline #454122 passed with warnings
......@@ -468,62 +468,62 @@ class WorkflowState extends ConfigEntityBase implements WorkflowStateInterface {
*/
public function getOptions($entity, $field_name, AccountInterface $account = NULL, $force = FALSE, $use_cache = TRUE) {
$options = [];
$transitions = NULL;
// Define an Entity-specific cache per page load.
static $cache = [];
$entity_id = ($entity) ? $entity->id() ?? '' : '';
$entity_type_id = ($entity) ? $entity->getEntityTypeId() : '';
$current_sid = $this->id();
// Define an Entity-specific cache per page load.
static $cache = [];
// Get options from page cache, using a non-empty index (just to be sure).
$entity_index = (!$entity) ? 'x' : $entity_id;
if ($use_cache && isset($cache[$entity_type_id][$entity_index][$force][$current_sid])) {
$options = $cache[$entity_type_id][$entity_index][$force][$current_sid];
$entity_type_index = ($entity) ? $entity->getEntityTypeId() : 'x';
$entity_index = ($entity) ? $entity->id() ?? 'x' : 'x';
$sid_index = $current_sid ?? 'x';
if ($use_cache && isset($cache[$entity_type_index][$entity_index][$force][$sid_index])) {
$options = $cache[$entity_type_index][$entity_index][$force][$sid_index];
return $options;
}
// No workflow, no options ;-)
$workflow = $this->getWorkflow();
if (!$workflow) {
// No workflow, no options ;-)
return $options;
}
if (!$current_sid) {
// If no State ID is given, we return all states.
// If no State ID is given (on Field settings page), we return all states.
// We cannot use getTransitions, since there are no ConfigTransitions
// from State with ID 0, and we do not want to repeat States.
// @see https://www.drupal.org/project/workflow/issues/3119998
// @see WorkflowState::__toString().
$options = $workflow->getStates(WorkflowInterface::ACTIVE_CREATION_STATES);
return $options;
}
elseif ($current_sid) {
$transitions = $this->getTransitions($entity, $field_name, $account, $force);
}
elseif ($entity->{$field_name}->value ?? NULL) {
// Note Avoid recursive calling.
// @todo Is this code now obsolete in v1.19?
$transition = $entity->{$field_name}->first()->getTransition();
$transitions = $this->getTransitions($transition, $field_name, $account, $force);
}
else {
if ($entity instanceof WorkflowTransitionInterface) {
$transition = $entity;
$transitions = $this->getTransitions($transition, $field_name, $account, $force);
}
elseif ($entity->{$field_name}->value) {
$transition = $entity->{$field_name}->first()->getTransition();
$transitions = $this->getTransitions($transition, $field_name, $account, $force);
}
else {
// Empty field. Entity is created before enabling Workflow module.
$options = $workflow->getStates();
return $options;
}
// Empty field. Entity is created before enabling Workflow module.
$options = $workflow->getStates();
}
// Return the transitions (for better label()), with state ID.
// Return the transitions (for better label()), with state ID.
if (is_array($transitions)) {
foreach ($transitions as $transition) {
$to_sid = $transition->to_sid;
// @see WorkflowConfigTransition::__toString().
$options[$to_sid] = $transition;
}
// Save to entity-specific cache.
$cache[$entity_type_id][$entity_index][$force][$current_sid] = $options;
}
// Save to entity-specific cache.
$cache[$entity_type_index][$entity_index][$force][$sid_index] = $options;
return $options;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment