function template_preprocess_views_view_opml

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

Prepares variables for OPML feed templates.

Default template: views-view-opml.html.twig.

Parameters

array $variables: An associative array containing:

  • view: A ViewExecutable object.
  • rows: The raw row data.

File

core/modules/views/views.theme.inc, line 942

Code

function template_preprocess_views_view_opml(&$variables) {
    $view = $variables['view'];
    $items = $variables['rows'];
    $config = \Drupal::config('system.site');
    if ($view->display_handler
        ->getOption('sitename_title')) {
        $title = $config->get('name');
        if ($slogan = $config->get('slogan')) {
            $title .= ' - ' . $slogan;
        }
    }
    else {
        $title = $view->getTitle();
    }
    $variables['title'] = $title;
    $variables['items'] = $items;
    $variables['updated'] = gmdate(DATE_RFC2822, \Drupal::time()->getRequestTime());
    // During live preview we don't want to output the header since the contents
    // of the feed are being displayed inside a normal HTML page.
    if (empty($variables['view']->live_preview)) {
        $variables['view']->getResponse()->headers
            ->set('Content-Type', 'text/xml; charset=utf-8');
    }
}

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