diff --git a/core/modules/forum/src/Controller/ForumController.php b/core/modules/forum/src/Controller/ForumController.php index 9efb774..db3c888 100644 --- a/core/modules/forum/src/Controller/ForumController.php +++ b/core/modules/forum/src/Controller/ForumController.php @@ -76,14 +76,11 @@ class ForumController extends ControllerBase { protected $renderer; /** + * Node entity type, we need to get cache tags from here. + * * @var \Drupal\Core\Entity\EntityTypeInterface */ - protected $nodeListDefinition; - - /** - * @var \Drupal\Core\Entity\EntityTypeInterface - */ - protected $nodeDefinition; + protected $nodeEntityTypeDefinition; /** * Constructs a ForumController object. @@ -104,12 +101,10 @@ class ForumController extends ControllerBase { * Node type storage handler. * @param \Drupal\Core\Render\RendererInterface $renderer * The renderer. - * @param \Drupal\Core\Entity\EntityTypeInterface $node_definition - * Node definition object - * @param \Drupal\Core\Entity\EntityTypeInterface $node_list_definition - * Node list definition object + * @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, EntityTypeInterface $node_definition, EntityTypeInterface $node_list_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) { $this->forumManager = $forum_manager; $this->vocabularyStorage = $vocabulary_storage; $this->termStorage = $term_storage; @@ -118,8 +113,7 @@ public function __construct(ForumManagerInterface $forum_manager, VocabularyStor $this->fieldMap = $field_map; $this->nodeTypeStorage = $node_type_storage; $this->renderer = $renderer; - $this->nodeDefinition = $node_definition; - $this->nodeListDefinition = $node_list_definition; + $this->nodeEntityTypeDefinition = $node_entity_type_definition; } /** @@ -138,8 +132,7 @@ 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_type') + $entity_manager->getDefinition('node') ); } @@ -229,7 +222,7 @@ protected function build($forums, TermInterface $term, $topics = array(), $paren 'action' => $this->buildActionLinks($config->get('vocabulary'), $term), 'forum' => $build, '#cache' => [ - 'tags' => Cache::mergeTags($this->nodeDefinition->getListCacheTags(), $this->nodeListDefinition->getListCacheTags()), + 'tags' => $this->nodeEntityTypeDefinition->getListCacheTags(), ], ]; } @@ -282,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', @@ -291,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 57d5ba7..5ec7a79 100644 --- a/core/modules/forum/src/Tests/ForumIndexTest.php +++ b/core/modules/forum/src/Tests/ForumIndexTest.php @@ -59,7 +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'); + $this->assertCacheTag('config:node.type.forum'); // Unpublish the node. $this->drupalPostForm('node/' . $node->id() . '/edit', array(), t('Save and unpublish'));