diff --git a/src/Plugin/views/argument/TaxonomyEntityIndexDepth.php b/src/Plugin/views/argument/TaxonomyEntityIndexDepth.php index 474158180b4624a7aa667414ab6e00e22c724814..00f96fb4aedce9dc7ba67ccdf575dccd0d36180b 100644 --- a/src/Plugin/views/argument/TaxonomyEntityIndexDepth.php +++ b/src/Plugin/views/argument/TaxonomyEntityIndexDepth.php @@ -9,6 +9,7 @@ use Drupal\Core\Database\Query\Condition; use Drupal\Core\Entity\EntityRepositoryInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\taxonomy\Plugin\views\argument\IndexTidDepth; +use Drupal\Core\Form\FormStateInterface; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ViewExecutable; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -57,6 +58,28 @@ abstract class TaxonomyEntityIndexDepth extends IndexTidDepth { $this->baseTableInfo = $this->viewsData->get($this->table); } + /** + * {@inhritdoc} + */ + protected function defineOptions() { + $options = parent::defineOptions(); + $options['field_names'] = ['default' => '']; + return $options; + } + + /** + * {@inheritdoc} + */ + public function buildOptionsForm(&$form, FormStateInterface $form_state) { + $form['field_names'] = [ + '#type' => 'textfield', + '#title' => $this->t('Excluded Field Names'), + '#default_value' => $this->options['field_names'], + '#description' => $this->t("Enter field names, separated by commas, that should be excluded from results. If content references taxonomy by the provided field name(s) they will be filtered out of the results. This is useful to ignore certain fields, particularly if content references the same Vocabulary using more than one field."), + ]; + parent::buildOptionsForm($form, $form_state); + } + /** * {@inheritdoc} */ @@ -106,6 +129,16 @@ abstract class TaxonomyEntityIndexDepth extends IndexTidDepth { $subquery->condition($where); + // Add conditional for field_names if configured. + if (!empty($this->options['field_names'])) { + $field_names = array_filter(array_map('trim', explode(',', $this->options['field_names']))); + $andFieldNames = new Condition('AND'); + foreach ($field_names as $field_name) { + $andFieldNames->condition('tn.field_name', $field_name, '!='); + } + $subquery->condition($andFieldNames); + } + $this->query->addWhere(0, "$this->tableAlias.$real_field", $subquery, 'IN'); }