diff -u b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php --- b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php +++ b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php @@ -388,7 +388,9 @@ public function getCacheTags() { $cache_tags = parent::getCacheTags(); $vocabulary = $this->vocabularyStorage->load($this->options['vid']); - $cache_tags += $vocabulary->getCacheTags(); + if ($vocabulary) { + $cache_tags += $vocabulary->getCacheTags(); + } // There is no vocabulary specific tag for 'taxonomy_term_list' so we add // the generic tag here to catch any updates to tags. $cache_tags[] = 'taxonomy_term_list'; only in patch2: unchanged: --- a/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyIndexTidFilterTest.php +++ b/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyIndexTidFilterTest.php @@ -24,7 +24,7 @@ class TaxonomyIndexTidFilterTest extends TaxonomyTestBase { /** * {@inheritdoc} */ - public static $testViews = ['test_filter_taxonomy_index_tid__non_existing_dependency']; + public static $testViews = ['test_filter_taxonomy_index_tid__non_existing_dependency', 'test_filter_taxonomy_index_tid']; /** * @var \Drupal\taxonomy\TermInterface[] @@ -153,4 +153,21 @@ public function testPostUpdateFunction() { ], $view->getDependencies()); } + /** + * Tests that the cache tags for the chosen vocabulary are added. + */ + public function testGetCacheTags() { + /** @var \Drupal\views\Entity\View $view */ + $view = View::load('test_filter_taxonomy_index_tid'); + $view_executable = $view->getExecutable(); + $view_executable->initDisplay(); + $cache_metadata = $view_executable->getDisplay()->calculateCacheMetadata(); + + $expected_cache_tags = [ + 'config:taxonomy.vocabulary.tags', + 'taxonomy_term_list', + ]; + $this->assertEquals($expected_cache_tags, $cache_metadata->getCacheTags()); + } + }