You are here

protected function PageEditWizard::actions in Page Manager 8

Same name and namespace in other branches
  1. 8.4 page_manager_ui/src/Wizard/PageEditWizard.php \Drupal\page_manager_ui\Wizard\PageEditWizard::actions()

Generates action elements for navigating between the operation steps.

Parameters

\Drupal\Core\Form\FormInterface $form_object: The current operation form.

\Drupal\Core\Form\FormStateInterface $form_state: The current form state.

Return value

array

Overrides FormWizardBase::actions

File

page_manager_ui/src/Wizard/PageEditWizard.php, line 188
Contains \Drupal\page_manager_ui\Wizard\PageEditWizard.

Class

PageEditWizard

Namespace

Drupal\page_manager_ui\Wizard

Code

protected function actions(FormInterface $form_object, FormStateInterface $form_state) {
  $cached_values = $form_state
    ->getTemporaryValue('wizard');
  $operation = $this
    ->getOperation($cached_values);
  $actions = [];
  $actions['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Update'),
    '#validate' => [
      '::populateCachedValues',
      [
        $form_object,
        'validateForm',
      ],
    ],
    '#submit' => [
      [
        $form_object,
        'submitForm',
      ],
    ],
  ];
  $actions['update_and_save'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Update and save'),
    '#button_type' => 'primary',
    '#validate' => [
      '::populateCachedValues',
      [
        $form_object,
        'validateForm',
      ],
    ],
    '#submit' => [
      [
        $form_object,
        'submitForm',
      ],
    ],
  ];
  $actions['finish'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
    '#validate' => [
      '::populateCachedValues',
      [
        $form_object,
        'validateForm',
      ],
    ],
    '#submit' => [
      [
        $form_object,
        'submitForm',
      ],
    ],
  ];
  $actions['cancel'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Cancel'),
    '#submit' => [
      '::clearTempstore',
    ],
  ];

  // Add any submit or validate functions for the step and the global ones.
  foreach ([
    'submit',
    'update_and_save',
    'finish',
  ] as $button) {
    if (isset($operation['validate'])) {
      $actions[$button]['#validate'] = array_merge($actions[$button]['#validate'], $operation['validate']);
    }
    $actions[$button]['#validate'][] = '::validateForm';
    if (isset($operation['submit'])) {
      $actions[$button]['#submit'] = array_merge($actions[$button]['#submit'], $operation['submit']);
    }
    $actions[$button]['#submit'][] = '::submitForm';
  }
  $actions['update_and_save']['#submit'][] = '::finish';
  $actions['finish']['#submit'][] = '::finish';
  if ($form_state
    ->get('ajax')) {
    $cached_values = $form_state
      ->getTemporaryValue('wizard');
    $ajax_parameters = $this
      ->getNextParameters($cached_values);
    $ajax_parameters['step'] = $this
      ->getStep($cached_values);
    $actions['submit']['#ajax'] = [
      'callback' => '::ajaxSubmit',
      'url' => Url::fromRoute($this
        ->getRouteName(), $ajax_parameters),
      'options' => [
        'query' => \Drupal::request()->query
          ->all() + [
          FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
        ],
      ],
    ];
    $actions['update_and_save']['#ajax'] = [
      'callback' => '::ajaxFinish',
      'url' => Url::fromRoute($this
        ->getRouteName(), $ajax_parameters),
      'options' => [
        'query' => \Drupal::request()->query
          ->all() + [
          FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
        ],
      ],
    ];
    $actions['finish']['#ajax'] = [
      'callback' => '::ajaxFinish',
      'url' => Url::fromRoute($this
        ->getRouteName(), $ajax_parameters),
      'options' => [
        'query' => \Drupal::request()->query
          ->all() + [
          FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
        ],
      ],
    ];
  }
  return $actions;
}