public function WorkflowTransitionAddForm::save in Drupal 9
Same name and namespace in other branches
- 8 core/modules/workflows/src/Form/WorkflowTransitionAddForm.php \Drupal\workflows\Form\WorkflowTransitionAddForm::save()
Form submission handler for the 'save' action.
Normally this method should be overridden to provide specific messages to the user and redirect the form after the entity has been saved.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.
Overrides EntityForm::save
File
- core/
modules/ workflows/ src/ Form/ WorkflowTransitionAddForm.php, line 176
Class
- WorkflowTransitionAddForm
- Entity form variant for adding workflow transitions.
Namespace
Drupal\workflows\FormCode
public function save(array $form, FormStateInterface $form_state) {
/** @var \Drupal\workflows\WorkflowInterface $workflow */
$workflow = $this->entity;
$workflow_type = $workflow
->getTypePlugin();
$transition = $workflow_type
->getTransition($form_state
->getValue('id'));
if ($workflow_type
->hasFormClass(TransitionInterface::PLUGIN_FORM_KEY)) {
$subform_state = SubformState::createForSubform($form['type_settings'], $form, $form_state);
$subform_state
->set('transition', $transition);
$this->pluginFormFactory
->createInstance($workflow_type, TransitionInterface::PLUGIN_FORM_KEY)
->submitConfigurationForm($form['type_settings'], $subform_state);
}
$workflow
->save();
$this
->messenger()
->addStatus($this
->t('Created %label transition.', [
'%label' => $form_state
->getValue('label'),
]));
$form_state
->setRedirectUrl($workflow
->toUrl('edit-form'));
}