diff --git a/core/modules/forum/src/Controller/ForumController.php b/core/modules/forum/src/Controller/ForumController.php index 7a17292..b5bfec6 100644 --- a/core/modules/forum/src/Controller/ForumController.php +++ b/core/modules/forum/src/Controller/ForumController.php @@ -11,6 +11,7 @@ use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Entity\EntityAccessControlHandlerInterface; use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Render\RendererInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Url; @@ -75,6 +76,16 @@ class ForumController extends ControllerBase { protected $renderer; /** + * @var \Drupal\Core\Entity\EntityTypeInterface + */ + private $nodeListDefinition; + + /** + * @var \Drupal\Core\Entity\EntityTypeInterface + */ + private $nodeDefinition; + + /** * Constructs a ForumController object. * * @param \Drupal\forum\ForumManagerInterface $forum_manager @@ -93,10 +104,12 @@ class ForumController extends ControllerBase { * Node type storage handler. * @param \Drupal\Core\Render\RendererInterface $renderer * The renderer. - * @param array $node_list_cache_tags - * Array of node list cache tags. + * @param \Drupal\Core\Entity\EntityTypeInterface $node_definition + * Node definition object + * @param \Drupal\Core\Entity\EntityTypeInterface $node_list_definition + * Node list definition object */ - public function __construct(ForumManagerInterface $forum_manager, VocabularyStorageInterface $vocabulary_storage, TermStorageInterface $term_storage, AccountInterface $current_user, EntityAccessControlHandlerInterface $node_access, array $field_map, EntityStorageInterface $node_type_storage, RendererInterface $renderer, array $node_list_cache_tags) { + public function __construct(ForumManagerInterface $forum_manager, VocabularyStorageInterface $vocabulary_storage, TermStorageInterface $term_storage, AccountInterface $current_user, EntityAccessControlHandlerInterface $node_access, array $field_map, EntityStorageInterface $node_type_storage, RendererInterface $renderer, EntityTypeInterface $node_definition, EntityTypeInterface $node_list_definition) { $this->forumManager = $forum_manager; $this->vocabularyStorage = $vocabulary_storage; $this->termStorage = $term_storage; @@ -105,7 +118,8 @@ public function __construct(ForumManagerInterface $forum_manager, VocabularyStor $this->fieldMap = $field_map; $this->nodeTypeStorage = $node_type_storage; $this->renderer = $renderer; - $this->nodeListCacheTags = $node_list_cache_tags; + $this->nodeDefinition = $node_definition; + $this->nodeListDefinition = $node_list_definition; } /** @@ -114,6 +128,7 @@ public function __construct(ForumManagerInterface $forum_manager, VocabularyStor public static function create(ContainerInterface $container) { /** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */ $entity_manager = $container->get('entity.manager'); + $tags = $entity_manager->getDefinition('taxonomy_term')->getListCacheTags(); return new static( $container->get('forum_manager'), $entity_manager->getStorage('taxonomy_vocabulary'), @@ -123,7 +138,8 @@ public static function create(ContainerInterface $container) { $entity_manager->getFieldMap(), $entity_manager->getStorage('node_type'), $container->get('renderer'), - $entity_manager->getDefinition('node')->getListCacheTags() + $entity_manager->getDefinition('node'), + $entity_manager->getDefinition('node_type') ); } @@ -213,7 +229,7 @@ protected function build($forums, TermInterface $term, $topics = array(), $paren 'action' => $this->buildActionLinks($config->get('vocabulary'), $term), 'forum' => $build, '#cache' => [ - 'tags' => $this->nodeListCacheTags, + 'tags' => Cache::mergeTags($this->nodeDefinition->getListCacheTags(), $this->nodeListDefinition->getListCacheTags()), ], ]; } diff --git a/core/modules/forum/src/Tests/ForumIndexTest.php b/core/modules/forum/src/Tests/ForumIndexTest.php index 2dc0310..57d5ba7 100644 --- a/core/modules/forum/src/Tests/ForumIndexTest.php +++ b/core/modules/forum/src/Tests/ForumIndexTest.php @@ -59,6 +59,7 @@ function testForumIndexStatus() { $this->drupalGet('forum/' . $tid); $this->assertText($title, 'Published forum topic appears on index.'); $this->assertCacheTag('node_list'); + $this->assertCacheTag('config:node_type_list'); // Unpublish the node. $this->drupalPostForm('node/' . $node->id() . '/edit', array(), t('Save and unpublish'));