function ViewsUiThemeHooks::preprocessViewPreviewSection

Prepares variables for views UI view preview section templates.

Default template: views-ui-view-preview-section.html.twig.

Parameters

array $variables: An associative array containing:

  • view: The view object.
  • section: The section name of a View (e.g. title, rows or pager).

File

core/modules/views_ui/src/Hook/ViewsUiThemeHooks.php, line 590

Class

ViewsUiThemeHooks
Hook implementations for views_ui.

Namespace

Drupal\views_ui\Hook

Code

public function preprocessViewPreviewSection(array &$variables) : void {
  switch ($variables['section']) {
    case 'title':
      $variables['title'] = $this->t('Title');
      $links = $this->viewPreviewSectionDisplayCategoryLinks($variables['view'], 'title', $variables['title']);
      break;

    case 'header':
      $variables['title'] = $this->t('Header');
      $links = $this->viewPreviewSectionHandlerLinks($variables['view'], $variables['section']);
      break;

    case 'empty':
      $variables['title'] = $this->t('No results behavior');
      $links = $this->viewPreviewSectionHandlerLinks($variables['view'], $variables['section']);
      break;

    case 'exposed':
      // @todo Sorts can be exposed too, so we may need a better title.
      $variables['title'] = $this->t('Exposed Filters');
      $links = $this->viewPreviewSectionDisplayCategoryLinks($variables['view'], 'exposed_form_options', $variables['title']);
      break;

    case 'rows':
      // @todo The title needs to depend on what is being viewed.
      $variables['title'] = $this->t('Content');
      $links = $this->viewPreviewSectionRowsLinks($variables['view']);
      break;

    case 'pager':
      $variables['title'] = $this->t('Pager');
      $links = $this->viewPreviewSectionDisplayCategoryLinks($variables['view'], 'pager_options', $variables['title']);
      break;

    case 'more':
      $variables['title'] = $this->t('More');
      $links = $this->viewPreviewSectionDisplayCategoryLinks($variables['view'], 'use_more', $variables['title']);
      break;

    case 'footer':
      $variables['title'] = $this->t('Footer');
      $links = $this->viewPreviewSectionHandlerLinks($variables['view'], $variables['section']);
      break;

    case 'attachment_before':
      // @todo Add links to the attachment configuration page.
      $variables['title'] = $this->t('Attachment before');
      break;

    case 'attachment_after':
      // @todo Add links to the attachment configuration page.
      $variables['title'] = $this->t('Attachment after');
      break;

  }
  if (isset($links)) {
    $build = [
      '#theme' => 'links__contextual',
      '#links' => $links,
      '#attributes' => [
        'class' => [
          'contextual-links',
        ],
      ],
      '#attached' => [
        'library' => [
          'contextual/drupal.contextual-links',
        ],
      ],
    ];
    $variables['links'] = $build;
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.