Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
workflow
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
workflow
Commits
13621603
Commit
13621603
authored
1 year ago
by
John Voskuilen
Browse files
Options
Downloads
Patches
Plain Diff
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
1 year ago
Stage: build
Stage: validate
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Element/WorkflowTransitionElement.php
+36
-14
36 additions, 14 deletions
src/Element/WorkflowTransitionElement.php
with
36 additions
and
14 deletions
src/Element/WorkflowTransitionElement.php
+
36
−
14
View file @
13621603
...
...
@@ -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
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment