You are here

function template_preprocess_panelizer_view_mode in Panelizer 8.3

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

Preprocess function for panelizer-view-mode.html.twig

Prepare variables for Panelizer view mode templates.

File

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

Code

function template_preprocess_panelizer_view_mode(&$variables) {
  $element = $variables['element'];

  // Copy values into the variables.

  /** @var \Drupal\panelizer\Plugin\PanelizerEntityInterface $panelizer_plugin */
  $panelizer_plugin = $variables['panelizer_plugin'] = $element['#panelizer_plugin'];

  /** @var \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display */
  $panels_display = $variables['panels_display'] = $element['#panels_display'];

  /** @var \Drupal\Core\Entity\EntityInterface $entity */
  $entity = $variables['entity'] = $element['#entity'];
  $view_mode = $variables['view_mode'] = $element['#view_mode'];
  $variables['content'] = $element['content'];
  $variables['title'] = isset($element['#title']) ? $element['#title'] : '';

  // Setup the defaults.
  $variables['title_element'] = 'h2';
  $variables['entity_url'] = $entity
    ->toUrl('canonical', [
    'language' => $entity
      ->language(),
  ]);

  // Allow the Panelizer entity plugin to do additional preprocessing.
  $panelizer_plugin
    ->preprocessViewMode($variables, $entity, $panels_display, $view_mode);
}