You are here

function template_preprocess_panelizer_wizard_tree in Panelizer 8.3

Same name and namespace in other branches
  1. 8.5 panelizer.module \template_preprocess_panelizer_wizard_tree()
  2. 8.4 panelizer.module \template_preprocess_panelizer_wizard_tree()

Preprocess function for panelizer-wizard-tree.html.twig.

File

./panelizer.module, line 342
Hook implementations for the Panelizer module.

Code

function template_preprocess_panelizer_wizard_tree(&$variables) {

  /** @var $wizard \Drupal\ctools\Wizard\FormWizardInterface|\Drupal\ctools\Wizard\EntityFormWizardInterface */
  $wizard = $variables['wizard'];
  $cached_values = $variables['cached_values'];
  $tree = $variables['tree'];
  $variables['step'] = $wizard
    ->getStep($cached_values);
  foreach ($wizard
    ->getOperations($cached_values) as $step => $operation) {
    $parameters = $wizard
      ->getNextParameters($cached_values);

    // Override step to be the step we want.
    $parameters['step'] = $step;

    // Fill in parents if there are breadcrumbs.
    $parent =& $tree;
    if (isset($operation['breadcrumbs'])) {
      foreach ($operation['breadcrumbs'] as $breadcrumb) {
        $breadcrumb_string = (string) $breadcrumb;
        if (!isset($parent[$breadcrumb_string])) {
          $parent[$breadcrumb_string] = [
            'title' => $breadcrumb,
            'children' => [],
          ];
        }
        $parent =& $parent[$breadcrumb_string]['children'];
      }
    }
    $parent[$step] = [
      'title' => !empty($operation['title']) ? $operation['title'] : '',
      'url' => new Url($wizard
        ->getRouteName(), $parameters),
      'step' => $step,
    ];
  }
  $variables['tree'] = $tree;
}