X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fviews%2Fsrc%2FPlugin%2Fviews%2Ffilter%2FManyToOne.php;fp=web%2Fcore%2Fmodules%2Fviews%2Fsrc%2FPlugin%2Fviews%2Ffilter%2FManyToOne.php;h=e678dee82f3f9c38ee6be2f6059bc4a79ec477f4;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/views/src/Plugin/views/filter/ManyToOne.php b/web/core/modules/views/src/Plugin/views/filter/ManyToOne.php new file mode 100644 index 000000000..e678dee82 --- /dev/null +++ b/web/core/modules/views/src/Plugin/views/filter/ManyToOne.php @@ -0,0 +1,135 @@ +helper = new ManyToOneHelper($this); + } + + protected function defineOptions() { + $options = parent::defineOptions(); + + $options['operator']['default'] = 'or'; + $options['value']['default'] = []; + + if (isset($this->helper)) { + $this->helper->defineOptions($options); + } + else { + $helper = new ManyToOneHelper($this); + $helper->defineOptions($options); + } + + return $options; + } + + public function operators() { + $operators = [ + 'or' => [ + 'title' => $this->t('Is one of'), + 'short' => $this->t('or'), + 'short_single' => $this->t('='), + 'method' => 'opHelper', + 'values' => 1, + 'ensure_my_table' => 'helper', + ], + 'and' => [ + 'title' => $this->t('Is all of'), + 'short' => $this->t('and'), + 'short_single' => $this->t('='), + 'method' => 'opHelper', + 'values' => 1, + 'ensure_my_table' => 'helper', + ], + 'not' => [ + 'title' => $this->t('Is none of'), + 'short' => $this->t('not'), + 'short_single' => $this->t('<>'), + 'method' => 'opHelper', + 'values' => 1, + 'ensure_my_table' => 'helper', + ], + ]; + // if the definition allows for the empty operator, add it. + if (!empty($this->definition['allow empty'])) { + $operators += [ + 'empty' => [ + 'title' => $this->t('Is empty (NULL)'), + 'method' => 'opEmpty', + 'short' => $this->t('empty'), + 'values' => 0, + ], + 'not empty' => [ + 'title' => $this->t('Is not empty (NOT NULL)'), + 'method' => 'opEmpty', + 'short' => $this->t('not empty'), + 'values' => 0, + ], + ]; + } + + return $operators; + } + + protected $valueFormType = 'select'; + protected function valueForm(&$form, FormStateInterface $form_state) { + parent::valueForm($form, $form_state); + + if (!$form_state->get('exposed')) { + $this->helper->buildOptionsForm($form, $form_state); + } + } + + /** + * Override ensureMyTable so we can control how this joins in. + * The operator actually has influence over joining. + */ + public function ensureMyTable() { + // Defer to helper if the operator specifies it. + $info = $this->operators(); + if (isset($info[$this->operator]['ensure_my_table']) && $info[$this->operator]['ensure_my_table'] == 'helper') { + return $this->helper->ensureMyTable(); + } + + return parent::ensureMyTable(); + } + + protected function opHelper() { + if (empty($this->value)) { + return; + } + $this->helper->addFilter(); + } + +}