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

Issue #2919482: isolate Element::copyAttachedFields()

parent efd2140c
No related branches found
No related tags found
No related merge requests found
Pipeline #197817 passed with warnings
......@@ -357,7 +357,7 @@ class WorkflowTransitionElement extends FormElement {
// Note: when editing existing Transition, user may still change comments.
$comment = $values['comment'][0]['value'] ?? '';
// @todo Why is 'timestamp' empty at create Node - when is it unset?
$timestamp_values = $values['timestamp'][0]['value'] ?? ['scheduled' => false];
$timestamp_values = $values['timestamp'][0]['value'] ?? ['scheduled' => FALSE];
$is_scheduled = (bool) $timestamp_values['scheduled'];
$timestamp = WorkflowTransitionTimestamp::valueCallback($timestamp_values, $timestamp_values, $form_state);
......@@ -396,11 +396,41 @@ class WorkflowTransitionElement extends FormElement {
$transition->schedule($is_scheduled);
$transition->force($force);
}
// Add the attached fields to the transition.
// Caveat: This works automatically on a Workflow Form,
// but only with a hack on a widget.
// @todo This line seems necessary for node edit, not for node view.
// @todo Support 'attached fields' in ScheduledTransition.
$transition = self::copyAttachedFields($transition, $form, $form_state, $values);
// Update targetEntity's itemList with the workflow field in two formats.
$transition->updateEntity(); // jvo
// Update form_state, so core can update entity as well.
$to_sid = $transition->getToSid();
$form_state->setValue(['to_sid', 0, 'target_id'], $to_sid);
return $transition;
}
/**
* Adds the attached fields from the element to the transition.
*
* Caveat: This works automatically on a Workflow Form,
* but only with a hack on a widget.
* @todo This line seems necessary for node edit, not for node view.
* @todo Support 'attached fields' in ScheduledTransition.
*
* @param \Drupal\Core\Entity\EntityInterface $transition
* The transition object.
* @param array $form
* The form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
* @param array $values
* The field item.
*
* @return \Drupal\workflow\Entity\WorkflowTransitionInterface
* The updated Transition object.
*/
public static function copyAttachedFields(EntityInterface $transition, array $form, FormStateInterface $form_state, array $values) {
/** @var \Drupal\workflow\Entity\WorkflowTransitionInterface $transition */
$attached_fields = $transition->getAttachedFields();
/** @var \Drupal\Core\Field\Entity\BaseFieldOverride $field */
foreach ($attached_fields as $field_name => $field) {
......@@ -419,14 +449,6 @@ class WorkflowTransitionElement extends FormElement {
];
\Drupal::moduleHandler()->alter('copy_form_values_to_transition_field', $transition, $context);
}
// Update targetEntity's itemList with the workflow field in two formats.
$transition->updateEntity();
// Update form_state, so core can update entity as well.
$to_sid = $transition->getToSid();
$form_state->setValue(['to_sid', 0, 'target_id'], $to_sid);
return $transition;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment