function WorkflowAddForm::save

Same name and namespace in other branches
  1. 8.9.x core/modules/workflows/src/Form/WorkflowAddForm.php \Drupal\workflows\Form\WorkflowAddForm::save()
  2. 10 core/modules/workflows/src/Form/WorkflowAddForm.php \Drupal\workflows\Form\WorkflowAddForm::save()
  3. 11.x core/modules/workflows/src/Form/WorkflowAddForm.php \Drupal\workflows\Form\WorkflowAddForm::save()

Overrides EntityForm::save

File

core/modules/workflows/src/Form/WorkflowAddForm.php, line 84

Class

WorkflowAddForm
Form for adding workflows.

Namespace

Drupal\workflows\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  /** @var \Drupal\workflows\WorkflowInterface $workflow */
  $workflow = $this->entity;
  $return = $workflow->save();
  if (empty($workflow->getTypePlugin()
    ->getStates())) {
    $this->messenger()
      ->addStatus($this->t('Created the %label Workflow. In order for the workflow to be enabled there needs to be at least one state.', [
      '%label' => $workflow->label(),
    ]));
    $form_state->setRedirectUrl($workflow->toUrl('add-state-form'));
  }
  else {
    $this->messenger()
      ->addStatus($this->t('Created the %label Workflow.', [
      '%label' => $workflow->label(),
    ]));
    $form_state->setRedirectUrl($workflow->toUrl('edit-form'));
  }
  return $return;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.