Commit 478f3390 authored by catch's avatar catch

Issue #3101738 by Lendude, jannakha, alexpott, daffie, bkosborne, Berdir:...

Issue #3101738 by Lendude, jannakha, alexpott, daffie, bkosborne, Berdir: Exposed term filters should not show term options that the user does not have access to

(cherry picked from commit 639a8ec8)
parent 282a7ee4
......@@ -181,6 +181,9 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
if ($tree) {
foreach ($tree as $term) {
if (!$term->isPublished()) {
continue;
}
$choice = new \stdClass();
$choice->option = [$term->id() => str_repeat('-', $term->depth) . \Drupal::service('entity.repository')->getTranslationFromContext($term)->label()];
$options[] = $choice;
......@@ -190,6 +193,7 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
else {
$options = [];
$query = \Drupal::entityQuery('taxonomy_term')
->condition('status', 1)
// @todo Sorting on vocabulary properties -
// https://www.drupal.org/node/1821274.
->sort('weight')
......
......@@ -231,4 +231,34 @@ public function testExposedFilter() {
$this->assertTrue(empty($preview), 'No results.');
}
/**
* Tests that an exposed taxonomy filter doesn't show unpublished terms.
*/
public function testExposedUnpublishedFilterOptions() {
$this->terms[1][0]->setUnpublished()->save();
// Expose the filter.
$this->drupalPostForm('admin/structure/views/nojs/handler/test_filter_taxonomy_index_tid/default/filter/tid', [], 'Expose filter');
$edit = ['options[expose_button][checkbox][checkbox]' => TRUE];
$this->drupalPostForm(NULL, $edit, 'Apply');
$this->drupalPostForm(NULL, [], 'Save');
$this->drupalLogout();
$this->drupalGet('test-filter-taxonomy-index-tid');
// Make sure the unpublished term isn't shown to the anonymous user.
$this->assertNotEmpty($this->cssSelect('option[value="' . $this->terms[0][0]->id() . '"]'));
$this->assertEmpty($this->cssSelect('option[value="' . $this->terms[1][0]->id() . '"]'));
// Tests that the term also isn't shown when not showing hierarchy.
$this->drupalLogin($this->adminUser);
$edit = [
'options[hierarchy]' => FALSE,
];
$this->drupalPostForm('admin/structure/views/nojs/handler-extra/test_filter_taxonomy_index_tid/default/filter/tid', $edit, 'Apply');
$this->drupalPostForm(NULL, [], 'Save');
$this->drupalLogout();
$this->drupalGet('test-filter-taxonomy-index-tid');
// Make sure the unpublished term isn't shown to the anonymous user.
$this->assertNotEmpty($this->cssSelect('option[value="' . $this->terms[0][0]->id() . '"]'));
$this->assertEmpty($this->cssSelect('option[value="' . $this->terms[1][0]->id() . '"]'));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment