.../aggregator/src/Plugin/Block/AggregatorFeedBlock.php | 1 + core/modules/book/src/Plugin/Block/BookNavigationBlock.php | 9 +++++++++ core/modules/forum/src/Plugin/Block/ForumBlockBase.php | 11 ++++++++++- core/modules/language/src/Plugin/Block/LanguageBlock.php | 9 +++++++++ core/modules/menu_ui/src/Tests/MenuTest.php | 6 ------ core/modules/node/node.module | 4 +++- core/modules/search/src/Plugin/Block/SearchBlock.php | 9 +++++++++ .../modules/system/src/Plugin/Block/SystemBreadcrumbBlock.php | 9 +++++++++ .../modules/form_test/src/Plugin/Block/RedirectFormBlock.php | 10 ++++++++++ core/modules/user/src/Plugin/Block/UserLoginBlock.php | 9 +++++++++ 10 files changed, 69 insertions(+), 8 deletions(-) diff --git a/core/modules/aggregator/src/Plugin/Block/AggregatorFeedBlock.php b/core/modules/aggregator/src/Plugin/Block/AggregatorFeedBlock.php index a4a6dc3..d2092a3 100644 --- a/core/modules/aggregator/src/Plugin/Block/AggregatorFeedBlock.php +++ b/core/modules/aggregator/src/Plugin/Block/AggregatorFeedBlock.php @@ -10,6 +10,7 @@ use Drupal\aggregator\FeedStorageInterface; use Drupal\aggregator\ItemStorageInterface; use Drupal\Core\Block\BlockBase; +use Drupal\Core\Cache\Cache; use Drupal\Core\Entity\Query\QueryInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; diff --git a/core/modules/book/src/Plugin/Block/BookNavigationBlock.php b/core/modules/book/src/Plugin/Block/BookNavigationBlock.php index 0c61e08..6718aec 100644 --- a/core/modules/book/src/Plugin/Block/BookNavigationBlock.php +++ b/core/modules/book/src/Plugin/Block/BookNavigationBlock.php @@ -190,4 +190,13 @@ public function getCacheContexts() { ]; } + /** + * {@inheritdoc} + * + * @todo Make cacheable as part of https://drupal.org/node/1805054 + */ + public function getCacheMaxAge() { + return 0; + } + } diff --git a/core/modules/forum/src/Plugin/Block/ForumBlockBase.php b/core/modules/forum/src/Plugin/Block/ForumBlockBase.php index e5937ce..ec5431a 100644 --- a/core/modules/forum/src/Plugin/Block/ForumBlockBase.php +++ b/core/modules/forum/src/Plugin/Block/ForumBlockBase.php @@ -87,7 +87,16 @@ public function blockSubmit($form, FormStateInterface $form_state) { * {@inheritdoc} */ public function getCacheKeys() { - return array_merge(parent::getCacheKeys(), Cache::keyFromQuery($this->buildForumQuery())); + $keys = parent::getCacheKeys(); + $keys[] = Cache::keyFromQuery($this->buildForumQuery()); + return $keys; + } + + /** + * {@inheritdoc} + */ + public function getCacheTags() { + return ['node_list']; } } diff --git a/core/modules/language/src/Plugin/Block/LanguageBlock.php b/core/modules/language/src/Plugin/Block/LanguageBlock.php index e86f263..7aa9bb8 100644 --- a/core/modules/language/src/Plugin/Block/LanguageBlock.php +++ b/core/modules/language/src/Plugin/Block/LanguageBlock.php @@ -107,4 +107,13 @@ public function build() { return $build; } + /** + * {@inheritdoc} + * + * @todo Make cacheable in https://drupal.org/node/2232375. + */ + public function getCacheMaxAge() { + return 0; + } + } diff --git a/core/modules/menu_ui/src/Tests/MenuTest.php b/core/modules/menu_ui/src/Tests/MenuTest.php index 5cb6563..9834792 100644 --- a/core/modules/menu_ui/src/Tests/MenuTest.php +++ b/core/modules/menu_ui/src/Tests/MenuTest.php @@ -578,12 +578,6 @@ public function testBlockContextualLinks() { $this->assertResponse(200); $json = Json::decode($response); $this->assertIdentical($json[$id], '
'); - - // Test the contextual links are available when block caching is enabled. - $this->drupalPostForm('admin/structure/block/manage/' . $block->id(), ['settings[cache][max_age]' => Cache::PERMANENT], t('Save block')); - $this->drupalGet('test-page'); - $id = 'block:block=' . $block->id() . ':|menu:menu=' . $custom_menu->id() . ':'; - $this->assertRaw('', format_string('Contextual link placeholder with id @id exists.', array('@id' => $id))); } /** diff --git a/core/modules/node/node.module b/core/modules/node/node.module index f181df1..a44d002 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -188,15 +188,17 @@ function node_entity_view_display_alter(EntityViewDisplayInterface $display, $co function node_title_list(StatementInterface $result, $title = NULL) { $items = array(); $num_rows = FALSE; + $nids = []; foreach ($result as $row) { // Do not use $node->label() or $node->urlInfo() here, because we only have // database rows, not actual nodes. + $nids[] = $row->nid; $options = !empty($row->comment_count) ? array('attributes' => array('title' => \Drupal::translation()->formatPlural($row->comment_count, '1 comment', '@count comments'))) : array(); $items[] = \Drupal::l($row->title, new Url('entity.node.canonical', ['node' => $row->nid], $options)); $num_rows = TRUE; } - return $num_rows ? array('#theme' => 'item_list__node', '#items' => $items, '#title' => $title) : FALSE; + return $num_rows ? array('#theme' => 'item_list__node', '#items' => $items, '#title' => $title, '#cache' => ['tags' => \Drupal\Core\Cache\Cache::buildTags('node', $nids)]) : FALSE; } /** diff --git a/core/modules/search/src/Plugin/Block/SearchBlock.php b/core/modules/search/src/Plugin/Block/SearchBlock.php index 369aad6..48a2b54 100644 --- a/core/modules/search/src/Plugin/Block/SearchBlock.php +++ b/core/modules/search/src/Plugin/Block/SearchBlock.php @@ -37,4 +37,13 @@ public function build() { return \Drupal::formBuilder()->getForm('Drupal\search\Form\SearchBlockForm'); } + /** + * {@inheritdoc} + * + * @todo Make cacheable once https://www.drupal.org/node/2351015 lands. + */ + public function getCacheMaxAge() { + return 0; + } + } diff --git a/core/modules/system/src/Plugin/Block/SystemBreadcrumbBlock.php b/core/modules/system/src/Plugin/Block/SystemBreadcrumbBlock.php index e822a72..b0cfe9a 100644 --- a/core/modules/system/src/Plugin/Block/SystemBreadcrumbBlock.php +++ b/core/modules/system/src/Plugin/Block/SystemBreadcrumbBlock.php @@ -84,4 +84,13 @@ public function build() { } } + /** + * {@inheritdoc} + * + * @todo Make cacheable as part of https://drupal.org/node/1805054 + */ + public function getCacheMaxAge() { + return 0; + } + } diff --git a/core/modules/system/tests/modules/form_test/src/Plugin/Block/RedirectFormBlock.php b/core/modules/system/tests/modules/form_test/src/Plugin/Block/RedirectFormBlock.php index 4a04599..f02b523 100644 --- a/core/modules/system/tests/modules/form_test/src/Plugin/Block/RedirectFormBlock.php +++ b/core/modules/system/tests/modules/form_test/src/Plugin/Block/RedirectFormBlock.php @@ -76,4 +76,14 @@ protected function blockAccess(AccountInterface $account) { public function build() { return $this->formBuilder->getForm('Drupal\form_test\Form\RedirectBlockForm'); } + + /** + * {@inheritdoc} + * + * @todo Make cacheable once https://www.drupal.org/node/2351015 lands. + */ + public function getCacheMaxAge() { + return 0; + } + } diff --git a/core/modules/user/src/Plugin/Block/UserLoginBlock.php b/core/modules/user/src/Plugin/Block/UserLoginBlock.php index 8fc92f0..64c4990 100644 --- a/core/modules/user/src/Plugin/Block/UserLoginBlock.php +++ b/core/modules/user/src/Plugin/Block/UserLoginBlock.php @@ -113,4 +113,13 @@ public function build() { ); } + /** + * {@inheritdoc} + * + * @todo Make cacheable once https://www.drupal.org/node/2351015 lands. + */ + public function getCacheMaxAge() { + return 0; + } + }