Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / entity_reference_revisions / src / Plugin / views / style / EntityReferenceRevisions.php
1 <?php
2
3 namespace Drupal\entity_reference_revisions\Plugin\views\style;
4
5 use Drupal\Component\Utility\Xss;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\views\Plugin\views\style\StylePluginBase;
8
9 /**
10  * EntityReferenceRevisions style plugin.
11  *
12  * @ingroup views_style_plugins
13  *
14  * @ViewsStyle(
15  *   id = "entity_reference_revisions",
16  *   title = @Translation("Entity Reference Revisions list"),
17  *   help = @Translation("Returns results as a PHP array of labels and rendered rows."),
18  *   theme = "views_view_unformatted",
19  *   register_theme = FALSE,
20  *   display_types = {"entity_reference_revisions"}
21  * )
22  */
23 class EntityReferenceRevisions extends StylePluginBase {
24
25   /**
26    * Overrides \Drupal\views\Plugin\views\style\StylePluginBase::usesRowPlugin.
27    */
28   protected $usesRowPlugin = TRUE;
29
30   /**
31    * Overrides \Drupal\views\Plugin\views\style\StylePluginBase::usesFields.
32    */
33   protected $usesFields = TRUE;
34
35   /**
36    * Overrides \Drupal\views\Plugin\views\style\StylePluginBase::usesGrouping.
37    */
38   protected $usesGrouping = FALSE;
39
40   /**
41    * Overrides \Drupal\views\Plugin\views\style\StylePluginBase\StylePluginBase::defineOptions().
42    */
43   protected function defineOptions() {
44     $options = parent::defineOptions();
45     $options['search_fields'] = array('default' => NULL);
46
47     return $options;
48   }
49
50   /**
51    * Overrides \Drupal\views\Plugin\views\style\StylePluginBase\StylePluginBase::buildOptionsForm().
52    */
53   public function buildOptionsForm(&$form, FormStateInterface $form_state) {
54     parent::buildOptionsForm($form, $form_state);
55
56     $options = $this->displayHandler->getFieldLabels(TRUE);
57     $form['search_fields'] = array(
58       '#type' => 'checkboxes',
59       '#title' => $this->t('Search fields'),
60       '#options' => $options,
61       '#required' => TRUE,
62       '#default_value' => $this->options['search_fields'],
63       '#description' => $this->t('Select the field(s) that will be searched when using the autocomplete widget.'),
64       '#weight' => -3,
65     );
66   }
67
68   /**
69    * Overrides \Drupal\views\Plugin\views\style\StylePluginBase\StylePluginBase::render().
70    */
71   public function render() {
72     if (!empty($this->view->live_preview)) {
73       return parent::render();
74     }
75
76     // Group the rows according to the grouping field, if specified.
77     $sets = $this->renderGrouping($this->view->result, $this->options['grouping']);
78
79     // Grab the alias of the 'id' field added by
80     // entity_reference_plugin_display.
81     $id_field_alias = $this->view->storage->get('base_field');
82
83     // @todo We don't display grouping info for now. Could be useful for select
84     // widget, though.
85     $results = array();
86     foreach ($sets as $records) {
87       foreach ($records as $values) {
88         // Sanitize HTML, remove line breaks and extra whitespace.
89         $output = $this->view->rowPlugin->render($values);
90         $output = \Drupal::service('renderer')->render($output);
91         $results[$values->{$id_field_alias}] = Xss::filterAdmin(preg_replace('/\s\s+/', ' ', str_replace("\n", '', $output)));
92       }
93     }
94     return $results;
95   }
96
97   /**
98    * {@inheritdoc}
99    */
100   public function evenEmpty() {
101     return TRUE;
102   }
103 }