You are here

public function PageVariantAddWizard::getOperations in Page Manager 8

Same name and namespace in other branches
  1. 8.4 page_manager_ui/src/Wizard/PageVariantAddWizard.php \Drupal\page_manager_ui\Wizard\PageVariantAddWizard::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 FormWizardInterface::getOperations

File

page_manager_ui/src/Wizard/PageVariantAddWizard.php, line 69
Contains \Drupal\page_manager_ui\Wizard\PageVariantAddWizard.

Class

PageVariantAddWizard

Namespace

Drupal\page_manager_ui\Wizard

Code

public function getOperations($cached_values) {
  $operations = [];
  $operations['type'] = [
    'title' => $this
      ->t('Page variant type'),
    'form' => PageVariantAddForm::class,
  ];
  $operations['contexts'] = [
    'title' => $this
      ->t('Contexts'),
    'form' => AddVariantContextsForm::class,
  ];
  $operations['selection'] = [
    'title' => $this
      ->t('Selection criteria'),
    'form' => AddVariantSelectionForm::class,
  ];
  $operations['configure'] = [
    'title' => $this
      ->t('Configure variant'),
    'form' => PageVariantConfigureForm::class,
  ];

  // Hide any optional steps that aren't selected.
  $optional_steps = [
    'selection',
    'contexts',
  ];
  foreach ($optional_steps as $step_name) {
    if (isset($cached_values['wizard_options']) && 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']) && !empty($cached_values['variant_plugin_id'])) {

    /** @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;
        $operations[$name] = $operation;
      }
    }
  }
  return $operations;
}