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

Issue #3508157: New transition - better use of...

Issue #3508157: New transition - better use of WorkflowTransition::baseFieldDefinition::DefaultValueCallback /2
parent 8d298e71
No related branches found
No related tags found
No related merge requests found
Pipeline #455678 passed with warnings
......@@ -93,8 +93,9 @@ class WorkflowTransitionForm extends ContentEntityForm {
\Drupal::messenger()->addWarning("The 'To state' cannot be disabled on the Transition Form and is enabled again.");
}
public static function trimWorkflowTransitionForm(array $workflow_form, WorkflowTransition $transition) {
public static function trimWorkflowTransitionForm(array $workflow_form) {
// Determine and add the attached fields.
$transition = $workflow_form['#default_value'];
$attached_fields = $transition->getAttachedFields();
// Then, remove all form elements, keep widget elements.
$base_fields = WorkflowTransition::baseFieldDefinitions($transition->getEntityType());
......
......@@ -154,7 +154,7 @@ abstract class WorkflowStateActionBase extends ConfigurableActionBase implements
$entity = $entity_type_manager->getStorage($entity_type_id)
->create(['type' => $entity_bundle]);
// Create the Transition with config data.
// Create the Transition with config data.
/** @var \Drupal\workflow\Entity\WorkflowTransitionInterface $transition */
$transition = workflow_get_transition($entity, $field_name);
// Update Transition without using $transition->setValues().
......
......@@ -96,7 +96,6 @@ class WorkflowDefaultWidget extends WidgetBase {
$entity = $item->getEntity();
$field_name = $field_storage->getName();
$transition = workflow_get_transition($entity, $field_name);
// To prepare the widget, use the Form, in order to get extra fields.
$form_state_additions = [
......@@ -104,8 +103,8 @@ class WorkflowDefaultWidget extends WidgetBase {
'values' => $form_state->getValues(),
'triggering_element' => $form_state->getTriggeringElement(),
];
$workflow_form = WorkflowTransitionForm::createInstance($entity, $field_name, $form_state_additions, $transition);
$element = WorkflowTransitionForm::trimWorkflowTransitionForm($workflow_form, $transition);
$workflow_form = WorkflowTransitionForm::createInstance($entity, $field_name, $form_state_additions);
$element = WorkflowTransitionForm::trimWorkflowTransitionForm($workflow_form);
return $element;
}
......
......@@ -131,7 +131,7 @@ function workflow_execute_transition(WorkflowTransitionInterface $transition, $f
* Gets the initial/resulting Transition of a workflow form/widget.
*/
function workflow_get_transition(EntityInterface $entity, $field_name, ?WorkflowTransitionInterface $transition = NULL): WorkflowTransitionInterface {
return WorkflowTargetEntity::getTransition($entity, $field_name, $transition);
return $transition ?? WorkflowTargetEntity::getTransition($entity, $field_name);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment