function template_preprocess_views_ui_view_preview_section

Same name and namespace in other branches
  1. 8.9.x core/modules/views_ui/views_ui.theme.inc \template_preprocess_views_ui_view_preview_section()
  2. 10 core/modules/views_ui/views_ui.theme.inc \template_preprocess_views_ui_view_preview_section()
  3. 11.x core/modules/views_ui/views_ui.theme.inc \template_preprocess_views_ui_view_preview_section()

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/views_ui.theme.inc, line 492

Code

function template_preprocess_views_ui_view_preview_section(&$variables) {
    switch ($variables['section']) {
        case 'title':
            $variables['title'] = t('Title');
            $links = views_ui_view_preview_section_display_category_links($variables['view'], 'title', $variables['title']);
            break;
        case 'header':
            $variables['title'] = t('Header');
            $links = views_ui_view_preview_section_handler_links($variables['view'], $variables['section']);
            break;
        case 'empty':
            $variables['title'] = t('No results behavior');
            $links = views_ui_view_preview_section_handler_links($variables['view'], $variables['section']);
            break;
        case 'exposed':
            // @todo Sorts can be exposed too, so we may need a better title.
            $variables['title'] = t('Exposed Filters');
            $links = views_ui_view_preview_section_display_category_links($variables['view'], 'exposed_form_options', $variables['title']);
            break;
        case 'rows':
            // @todo The title needs to depend on what is being viewed.
            $variables['title'] = t('Content');
            $links = views_ui_view_preview_section_rows_links($variables['view']);
            break;
        case 'pager':
            $variables['title'] = t('Pager');
            $links = views_ui_view_preview_section_display_category_links($variables['view'], 'pager_options', $variables['title']);
            break;
        case 'more':
            $variables['title'] = t('More');
            $links = views_ui_view_preview_section_display_category_links($variables['view'], 'use_more', $variables['title']);
            break;
        case 'footer':
            $variables['title'] = t('Footer');
            $links = views_ui_view_preview_section_handler_links($variables['view'], $variables['section']);
            break;
        case 'attachment_before':
            // @todo: Add links to the attachment configuration page.
            $variables['title'] = t('Attachment before');
            break;
        case 'attachment_after':
            // @todo: Add links to the attachment configuration page.
            $variables['title'] = 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.