diff --git a/core/modules/forum/src/Controller/ForumController.php b/core/modules/forum/src/Controller/ForumController.php index 38cc097..db3c888 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,13 @@ class ForumController extends ControllerBase { protected $renderer; /** + * Node entity type, we need to get cache tags from here. + * + * @var \Drupal\Core\Entity\EntityTypeInterface + */ + protected $nodeEntityTypeDefinition; + + /** * Constructs a ForumController object. * * @param \Drupal\forum\ForumManagerInterface $forum_manager @@ -93,8 +101,10 @@ class ForumController extends ControllerBase { * Node type storage handler. * @param \Drupal\Core\Render\RendererInterface $renderer * The renderer. + * @param \Drupal\Core\Entity\EntityTypeInterface $node_entity_type_definition + * Node 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) { + 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) { $this->forumManager = $forum_manager; $this->vocabularyStorage = $vocabulary_storage; $this->termStorage = $term_storage; @@ -103,6 +113,7 @@ public function __construct(ForumManagerInterface $forum_manager, VocabularyStor $this->fieldMap = $field_map; $this->nodeTypeStorage = $node_type_storage; $this->renderer = $renderer; + $this->nodeEntityTypeDefinition = $node_entity_type_definition; } /** @@ -111,6 +122,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'); + return new static( $container->get('forum_manager'), $entity_manager->getStorage('taxonomy_vocabulary'), @@ -119,7 +131,8 @@ public static function create(ContainerInterface $container) { $entity_manager->getAccessControlHandler('node'), $entity_manager->getFieldMap(), $entity_manager->getStorage('node_type'), - $container->get('renderer') + $container->get('renderer'), + $entity_manager->getDefinition('node') ); } @@ -208,6 +221,9 @@ protected function build($forums, TermInterface $term, $topics = array(), $paren return [ 'action' => $this->buildActionLinks($config->get('vocabulary'), $term), 'forum' => $build, + '#cache' => [ + 'tags' => $this->nodeEntityTypeDefinition->getListCacheTags(), + ], ]; } @@ -259,6 +275,7 @@ protected function buildActionLinks($vid, TermInterface $forum_term = NULL) { // Loop through all bundles for forum taxonomy vocabulary field. foreach ($this->fieldMap['node']['taxonomy_forums']['bundles'] as $type) { if ($this->nodeAccess->createAccess($type)) { + $node_type = $this->nodeTypeStorage->load($type); $links[$type] = [ '#attributes' => ['class' => ['action-links']], '#theme' => 'menu_local_action', @@ -268,6 +285,9 @@ protected function buildActionLinks($vid, TermInterface $forum_term = NULL) { ]), 'url' => Url::fromRoute('node.add', ['node_type' => $type]), ], + '#cache' => [ + 'tags' => $node_type->getCacheTags(), + ], ]; if ($forum_term && $forum_term->bundle() == $vid) { // We are viewing a forum term (specific forum), append the tid to diff --git a/core/modules/forum/src/Tests/ForumIndexTest.php b/core/modules/forum/src/Tests/ForumIndexTest.php index b9ee537..5ec7a79 100644 --- a/core/modules/forum/src/Tests/ForumIndexTest.php +++ b/core/modules/forum/src/Tests/ForumIndexTest.php @@ -58,6 +58,8 @@ function testForumIndexStatus() { // Verify that the node appears on the index. $this->drupalGet('forum/' . $tid); $this->assertText($title, 'Published forum topic appears on index.'); + $this->assertCacheTag('node_list'); + $this->assertCacheTag('config:node.type.forum'); // Unpublish the node. $this->drupalPostForm('node/' . $node->id() . '/edit', array(), t('Save and unpublish'));