diff --git a/core/modules/forum/src/Controller/ForumController.php b/core/modules/forum/src/Controller/ForumController.php index db3c888..6c1a308 100644 --- a/core/modules/forum/src/Controller/ForumController.php +++ b/core/modules/forum/src/Controller/ForumController.php @@ -83,6 +83,13 @@ class ForumController extends ControllerBase { protected $nodeEntityTypeDefinition; /** + * Comment entity type, we need to get cache tags from here. + * + * @var \Drupal\Core\Entity\EntityTypeInterface + */ + protected $commentEntityTypeDefinition; + + /** * Constructs a ForumController object. * * @param \Drupal\forum\ForumManagerInterface $forum_manager @@ -103,8 +110,10 @@ class ForumController extends ControllerBase { * The renderer. * @param \Drupal\Core\Entity\EntityTypeInterface $node_entity_type_definition * Node entity type definition object + * @param \Drupal\Core\Entity\EntityTypeInterface $comment_entity_type_definition + * Comment entity type 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, EntityTypeInterface $node_entity_type_definition) { + 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_entity_type_definition, EntityTypeInterface $comment_entity_type_definition) { $this->forumManager = $forum_manager; $this->vocabularyStorage = $vocabulary_storage; $this->termStorage = $term_storage; @@ -114,6 +123,7 @@ public function __construct(ForumManagerInterface $forum_manager, VocabularyStor $this->nodeTypeStorage = $node_type_storage; $this->renderer = $renderer; $this->nodeEntityTypeDefinition = $node_entity_type_definition; + $this->commentEntityTypeDefinition = $comment_entity_type_definition; } /** @@ -132,7 +142,8 @@ public static function create(ContainerInterface $container) { $entity_manager->getFieldMap(), $entity_manager->getStorage('node_type'), $container->get('renderer'), - $entity_manager->getDefinition('node') + $entity_manager->getDefinition('node'), + $entity_manager->getDefinition('comment') ); } @@ -218,11 +229,22 @@ protected function build($forums, TermInterface $term, $topics = array(), $paren } $this->renderer->addCacheableDependency($build, $config); + foreach ($forums as $forum) { + $this->renderer->addCacheableDependency($build, $forum); + } + foreach ($topics as $topic) { + $this->renderer->addCacheableDependency($build, $topic); + } + foreach ($parents as $parent) { + $this->renderer->addCacheableDependency($build, $parent); + } + $this->renderer->addCacheableDependency($build, $term); + return [ 'action' => $this->buildActionLinks($config->get('vocabulary'), $term), 'forum' => $build, '#cache' => [ - 'tags' => $this->nodeEntityTypeDefinition->getListCacheTags(), + 'tags' => Cache::mergeTags($this->nodeEntityTypeDefinition->getListCacheTags(), $this->commentEntityTypeDefinition->getListCacheTags()), ], ]; } diff --git a/core/modules/forum/src/Tests/ForumIndexTest.php b/core/modules/forum/src/Tests/ForumIndexTest.php index 5ec7a79..c2d6e4e 100644 --- a/core/modules/forum/src/Tests/ForumIndexTest.php +++ b/core/modules/forum/src/Tests/ForumIndexTest.php @@ -60,6 +60,7 @@ function testForumIndexStatus() { $this->assertText($title, 'Published forum topic appears on index.'); $this->assertCacheTag('node_list'); $this->assertCacheTag('config:node.type.forum'); + $this->assertCacheTag('comment_list'); // Unpublish the node. $this->drupalPostForm('node/' . $node->id() . '/edit', array(), t('Save and unpublish'));