Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / workflows / src / Form / WorkflowAddForm.php
index 56cbf699617659b53779af7a3038a6538633423a..47ad81212258fbb4fea1a0f8000da1c08bc3edd2 100644 (file)
@@ -11,6 +11,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
  * Form for adding workflows.
+ *
+ * @internal
  */
 class WorkflowAddForm extends EntityForm {
 
@@ -53,7 +55,6 @@ class WorkflowAddForm extends EntityForm {
       '#title' => $this->t('Label'),
       '#maxlength' => 255,
       '#default_value' => $workflow->label(),
-      '#description' => $this->t('Label for the Workflow.'),
       '#required' => TRUE,
     ];
 
@@ -65,9 +66,8 @@ class WorkflowAddForm extends EntityForm {
       ],
     ];
 
-    $workflow_types = array_map(function ($plugin_definition) {
-      return $plugin_definition['label'];
-    }, $this->workflowTypePluginManager->getDefinitions());
+    $workflow_types = array_column($this->workflowTypePluginManager->getDefinitions(), 'label', 'id');
+
     $form['workflow_type'] = [
       '#type' => 'select',
       '#title' => $this->t('Workflow type'),
@@ -84,17 +84,15 @@ class WorkflowAddForm extends EntityForm {
   public function save(array $form, FormStateInterface $form_state) {
     /* @var \Drupal\workflows\WorkflowInterface $workflow */
     $workflow = $this->entity;
-    // Initialize the workflow using the selected type plugin.
-    $workflow = $workflow->getTypePlugin()->initializeWorkflow($workflow);
     $return = $workflow->save();
-    if (empty($workflow->getStates())) {
-      drupal_set_message($this->t('Created the %label Workflow. In order for the workflow to be enabled there needs to be at least one state.', [
+    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 {
-      drupal_set_message($this->t('Created the %label Workflow.', [
+      $this->messenger()->addStatus($this->t('Created the %label Workflow.', [
         '%label' => $workflow->label(),
       ]));
       $form_state->setRedirectUrl($workflow->toUrl('edit-form'));