Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / views / src / Plugin / views / style / Opml.php
1 <?php
2
3 namespace Drupal\views\Plugin\views\style;
4
5 use Drupal\Core\Url;
6
7 /**
8  * Default style plugin to render an OPML feed.
9  *
10  * @ingroup views_style_plugins
11  *
12  * @ViewsStyle(
13  *   id = "opml",
14  *   title = @Translation("OPML Feed"),
15  *   help = @Translation("Generates an OPML feed from a view."),
16  *   theme = "views_view_opml",
17  *   display_types = {"feed"}
18  * )
19  */
20 class Opml extends StylePluginBase {
21
22   /**
23    * {@inheritdoc}
24    */
25   protected $usesRowPlugin = TRUE;
26
27   /**
28    * {@inheritdoc}
29    */
30   public function attachTo(array &$build, $display_id, Url $feed_url, $title) {
31     $display = $this->view->displayHandlers->get($display_id);
32     $url_options = [];
33     $input = $this->view->getExposedInput();
34     if ($input) {
35       $url_options['query'] = $input;
36     }
37     $url_options['absolute'] = TRUE;
38
39     $url = $feed_url->setOptions($url_options)->toString();
40     if ($display->hasPath()) {
41       if (empty($this->preview)) {
42         $build['#attached']['feed'][] = [$url, $title];
43       }
44     }
45     else {
46       $this->view->feedIcons[] = [
47         '#theme' => 'feed_icon',
48         '#url' => $url,
49         '#title' => $title,
50       ];
51     }
52   }
53
54   /**
55    * {@inheritdoc}
56    */
57   public function render() {
58     if (empty($this->view->rowPlugin)) {
59       debug('Drupal\views\Plugin\views\style\Opml: Missing row plugin');
60       return;
61     }
62     $rows = [];
63
64     foreach ($this->view->result as $row_index => $row) {
65       $this->view->row_index = $row_index;
66       $rows[] = $this->view->rowPlugin->render($row);
67     }
68
69     $build = [
70       '#theme' => $this->themeFunctions(),
71       '#view' => $this->view,
72       '#options' => $this->options,
73       '#rows' => $rows,
74     ];
75     unset($this->view->row_index);
76     return $build;
77   }
78
79 }