69679d3ce7bd734a47e230618bb45b5f279eb8ca
[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    * Does the style plugin for itself support to add fields to its output.
24    *
25    * @var bool
26    */
27   protected $usesRowPlugin = TRUE;
28
29   /**
30    * {@inheritdoc}
31    */
32   public function attachTo(array &$build, $display_id, Url $feed_url, $title) {
33     $display = $this->view->displayHandlers->get($display_id);
34     $url_options = [];
35     $input = $this->view->getExposedInput();
36     if ($input) {
37       $url_options['query'] = $input;
38     }
39     $url_options['absolute'] = TRUE;
40
41     $url = $feed_url->setOptions($url_options)->toString();
42     if ($display->hasPath()) {
43       if (empty($this->preview)) {
44         $build['#attached']['feed'][] = [$url, $title];
45       }
46     }
47     else {
48       $this->view->feedIcons[] = [
49         '#theme' => 'feed_icon',
50         '#url' => $url,
51         '#title' => $title,
52       ];
53     }
54   }
55
56   /**
57    * {@inheritdoc}
58    */
59   public function render() {
60     if (empty($this->view->rowPlugin)) {
61       debug('Drupal\views\Plugin\views\style\Opml: Missing row plugin');
62       return;
63     }
64     $rows = [];
65
66     foreach ($this->view->result as $row_index => $row) {
67       $this->view->row_index = $row_index;
68       $rows[] = $this->view->rowPlugin->render($row);
69     }
70
71     $build = [
72       '#theme' => $this->themeFunctions(),
73       '#view' => $this->view,
74       '#options' => $this->options,
75       '#rows' => $rows,
76     ];
77     unset($this->view->row_index);
78     return $build;
79   }
80
81 }