Skip to content
Snippets Groups Projects

Issue #3104318 by larowlan, cameronprince, gambry, Lendude: Create tests and a...

1 file
+ 33
0
Compare changes
  • Side-by-side
  • Inline
@@ -9,6 +9,7 @@ use Drupal\Core\Database\Query\Condition;
@@ -9,6 +9,7 @@ use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\taxonomy\Plugin\views\argument\IndexTidDepth;
use Drupal\taxonomy\Plugin\views\argument\IndexTidDepth;
 
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\ViewExecutable;
use Drupal\views\ViewExecutable;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -57,6 +58,28 @@ abstract class TaxonomyEntityIndexDepth extends IndexTidDepth {
@@ -57,6 +58,28 @@ abstract class TaxonomyEntityIndexDepth extends IndexTidDepth {
$this->baseTableInfo = $this->viewsData->get($this->table);
$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}
* {@inheritdoc}
*/
*/
@@ -106,6 +129,16 @@ abstract class TaxonomyEntityIndexDepth extends IndexTidDepth {
@@ -106,6 +129,16 @@ abstract class TaxonomyEntityIndexDepth extends IndexTidDepth {
$subquery->condition($where);
$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');
$this->query->addWhere(0, "$this->tableAlias.$real_field", $subquery, 'IN');
}
}
Loading