Backup of database 9 Nov 17
[yaffs-website] / web / modules / contrib / permissions_by_term / src / Plugin / views / filter / PermissionsByTerm.php
1 <?php
2
3 namespace Drupal\d8views\Plugin\views\filter;
4
5 use Drupal\views\Plugin\views\display\DisplayPluginBase;
6 use Drupal\views\Plugin\views\filter\InOperator;
7 use Drupal\views\ViewExecutable;
8
9 /**
10  * Filters by given list of node title options.
11  *
12  * @ingroup views_filter_handlers
13  *
14  * @ViewsFilter("d8views_node_titles")
15  */
16 class PermissionsByTerm extends InOperator {
17
18   /**
19    * {@inheritdoc}
20    */
21   public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
22     parent::init($view, $display, $options);
23     $this->valueTitle = t('Allowed node titles');
24     $this->definition['options callback'] = [$this, 'generateOptions'];
25   }
26
27   /**
28    * Override the query.
29    *
30    * So that no filtering takes place if the user doesn't
31    * select any options.
32    */
33   public function query() {
34     if (!empty($this->value)) {
35       parent::query();
36     }
37   }
38
39   /**
40    * Skip validation.
41    *
42    * If no options have been chosen so we can use it as a non-filter.
43    */
44   public function validate() {
45     if (!empty($this->value)) {
46       parent::validate();
47     }
48   }
49
50   /**
51    * Helper function that generates the options.
52    *
53    * @return array
54    *   Array keys are used to compare with the table field values.
55    */
56   public function generateOptions() {
57     return [
58       'my title' => 'my title',
59       'another title' => 'another title',
60     ];
61   }
62
63 }