You are here

public function PageAddWizard::getOperations in Page Manager 8

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

Retrieve a list of FormInterface classes by their step key in the wizard.

Parameters

mixed $cached_values: The values returned by $this->getTempstore()->get($this->getMachineName()); *.

Return value

array An associative array keyed on the step name with an array value with the following keys:

  • title (string): Human-readable title of the step.
  • form (string): Fully-qualified class name of the form for this step.
  • values (array): Optional array of cached values to override when on this step.
  • validate (array): Optional array of callables to be called when this step is validated.
  • submit (array): Optional array of callables to be called when this step is submitted.

Overrides PageWizardBase::getOperations

File

page_manager_ui/src/Wizard/PageAddWizard.php, line 27
Contains \Drupal\page_manager_ui\Wizard\PageAddWizard.

Class

PageAddWizard

Namespace

Drupal\page_manager_ui\Wizard

Code

public function getOperations($cached_values) {
  $operations = parent::getOperations($cached_values);

  // Add steps for selection and creating the first variant.
  $operations['contexts'] = [
    'title' => $this
      ->t('Contexts'),
    'form' => PageVariantContextsForm::class,
  ];
  $operations['selection'] = [
    'title' => $this
      ->t('Selection criteria'),
    'form' => PageVariantSelectionForm::class,
  ];
  $operations['display_variant'] = [
    'title' => $this
      ->t('Configure variant'),
    'form' => PageVariantConfigureForm::class,
  ];

  // Hide the Parameters step if there aren't any path parameters.
  if (isset($cached_values['page']) && !$cached_values['page']
    ->getParameterNames()) {
    unset($operations['parameters']);
  }

  // Hide any optional steps that aren't selected.
  $optional_steps = [
    'access',
    'contexts',
    'selection',
  ];
  foreach ($optional_steps as $step_name) {
    if (empty($cached_values['wizard_options'][$step_name])) {
      unset($operations[$step_name]);
    }
  }

  // Add any wizard operations from the plugin itself.
  if (!empty($cached_values['page_variant'])) {

    /** @var \Drupal\page_manager\PageVariantInterface $page_variant */
    $page_variant = $cached_values['page_variant'];
    $variant_plugin = $page_variant
      ->getVariantPlugin();
    if ($variant_plugin instanceof PluginWizardInterface) {
      if ($variant_plugin instanceof ContextAwareVariantInterface) {
        $variant_plugin
          ->setContexts($page_variant
          ->getContexts());
      }
      $cached_values['plugin'] = $variant_plugin;
      foreach ($variant_plugin
        ->getWizardOperations($cached_values) as $name => $operation) {
        $operation['values']['plugin'] = $variant_plugin;
        $operation['submit'][] = '::submitVariantStep';
        $operations[$name] = $operation;
      }
    }
  }
  return $operations;
}