diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 6c43b69..7b3a5a1 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -555,23 +555,6 @@ function forum_form_node_form_alter(&$form, &$form_state, $form_id) { } /** - * Render API callback: Lists nodes based on the element's #query property. - * - * This function can be used as a #pre_render callback. - * - * @see \Drupal\forum\Plugin\block\block\NewTopicsBlock::build() - * @see \Drupal\forum\Plugin\block\block\ActiveTopicsBlock::build() - */ -function forum_block_view_pre_render($elements) { - $result = $elements['#query']->execute(); - if ($node_title_list = node_title_list($result)) { - $elements['forum_list'] = $node_title_list; - $elements['forum_more'] = array('#theme' => 'more_link', '#url' => 'forum', '#title' => t('Read the latest forum topics.')); - } - return $elements; -} - -/** * Implements hook_preprocess_HOOK() for block.html.twig. */ function forum_preprocess_block(&$variables) { diff --git a/core/modules/forum/forum.views.inc b/core/modules/forum/forum.views.inc index fb79907..97ee6eb 100644 --- a/core/modules/forum/forum.views.inc +++ b/core/modules/forum/forum.views.inc @@ -17,6 +17,7 @@ function forum_views_data() { 'field' => 'nid', 'title' => t('Forum content'), 'access query tag' => 'node_access', + 'query metadata' => array('base_table' => 'forum_index'), ); $data['forum_index']['nid'] = array( diff --git a/core/modules/forum/lib/Drupal/forum/Plugin/Block/ActiveTopicsBlock.php b/core/modules/forum/lib/Drupal/forum/Plugin/Block/ActiveTopicsBlock.php deleted file mode 100644 index 769aeb7..0000000 --- a/core/modules/forum/lib/Drupal/forum/Plugin/Block/ActiveTopicsBlock.php +++ /dev/null @@ -1,39 +0,0 @@ -fields('f') - ->addTag('node_access') - ->addMetaData('base_table', 'forum_index') - ->orderBy('f.last_comment_timestamp', 'DESC') - ->range(0, $this->configuration['block_count']); - - return array( - drupal_render_cache_by_query($query, 'forum_block_view'), - ); - } - -} diff --git a/core/modules/forum/lib/Drupal/forum/Plugin/Block/NewTopicsBlock.php b/core/modules/forum/lib/Drupal/forum/Plugin/Block/NewTopicsBlock.php deleted file mode 100644 index 44622a1..0000000 --- a/core/modules/forum/lib/Drupal/forum/Plugin/Block/NewTopicsBlock.php +++ /dev/null @@ -1,39 +0,0 @@ -fields('f') - ->addTag('node_access') - ->addMetaData('base_table', 'forum_index') - ->orderBy('f.created', 'DESC') - ->range(0, $this->configuration['block_count']); - - return array( - drupal_render_cache_by_query($query, 'forum_block_view'), - ); - } - -} diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php index 47495e4..ccb807c 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php @@ -20,7 +20,7 @@ class ForumBlockTest extends WebTestBase { * * @var array */ - public static $modules = array('forum', 'block'); + public static $modules = array('forum', 'block', 'views'); /** * A user with various administrative privileges. @@ -59,7 +59,7 @@ public function testNewForumTopicsBlock() { $topics = $this->createForumTopics(); // Enable the new forum topics block. - $block = $this->drupalPlaceBlock('forum_new_block'); + $block = $this->drupalPlaceBlock('views_block:forum_topic_lists-block_2'); $this->drupalGet(''); $this->assertLink(t('More'), 0, 'New forum topics block has a "more"-link.'); @@ -69,22 +69,6 @@ public function testNewForumTopicsBlock() { foreach ($topics as $topic) { $this->assertLink($topic, 0, format_string('Forum topic @topic found in the "New forum topics" block.', array('@topic' => $topic))); } - - // Configure the new forum topics block to only show 2 topics. - $block->getPlugin()->setConfigurationValue('block_count', 2); - $block->save(); - - $this->drupalGet(''); - // We expect only the 2 most recent forum topics to appear in the "New forum - // topics" block. - for ($index = 0; $index < 5; $index++) { - if (in_array($index, array(3, 4))) { - $this->assertLink($topics[$index], 0, format_string('Forum topic @topic found in the "New forum topics" block.', array('@topic' => $topics[$index]))); - } - else { - $this->assertNoText($topics[$index], format_string('Forum topic @topic not found in the "New forum topics" block.', array('@topic' => $topics[$index]))); - } - } } /** @@ -113,7 +97,7 @@ public function testActiveForumTopicsBlock() { } // Enable the block. - $block = $this->drupalPlaceBlock('forum_active_block'); + $block = $this->drupalPlaceBlock('views_block:forum_topic_lists-block_1'); $this->drupalGet(''); $this->assertLink(t('More'), 0, 'Active forum topics block has a "more"-link.'); $this->assertLinkByHref('forum', 0, 'Active forum topics block has a "more"-link.'); @@ -129,23 +113,6 @@ public function testActiveForumTopicsBlock() { $this->assertNoText($topics[$index], format_string('Forum topic @topic not found in the "Active forum topics" block.', array('@topic' => $topics[$index]))); } } - - // Configure the active forum block to only show 2 topics. - $block->getPlugin()->setConfigurationValue('block_count', 2); - $block->save(); - - $this->drupalGet(''); - - // We expect only the 2 forum topics with most recent comments to appear in - // the "Active forum topics" block. - for ($index = 0; $index < 10; $index++) { - if (in_array($index, array(3, 4))) { - $this->assertLink($topics[$index], 0, 'Forum topic found in the "Active forum topics" block.'); - } - else { - $this->assertNoText($topics[$index], 'Forum topic not found in the "Active forum topics" block.'); - } - } } /** diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumNodeAccessTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumNodeAccessTest.php index 489cc1b..ffa05de 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumNodeAccessTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumNodeAccessTest.php @@ -19,7 +19,7 @@ class ForumNodeAccessTest extends WebTestBase { * * @var array */ - public static $modules = array('node', 'comment', 'forum', 'taxonomy', 'tracker', 'node_access_test', 'block'); + public static $modules = array('node', 'comment', 'forum', 'taxonomy', 'tracker', 'node_access_test', 'block', 'views'); public static function getInfo() { return array( @@ -72,8 +72,8 @@ function testForumNodeAccess() { // Enable the new and active forum blocks. - $this->drupalPlaceBlock('forum_active_block'); - $this->drupalPlaceBlock('forum_new_block'); + $this->drupalPlaceBlock('views_block:forum_topic_lists-block_1'); + $this->drupalPlaceBlock('views_block:forum_topic_lists-block_2'); // Test for $access_user. $this->drupalLogin($access_user); diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php b/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php index 7522c3f..aa0cf98 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php @@ -1376,6 +1376,12 @@ function execute(ViewExecutable $view) { $query->addTag($access_tag); $count_query->addTag($access_tag); } + + if (isset($base_table_data['table']['base']['query metadata'])) { + foreach ($base_table_data['table']['base']['query metadata'] as $key => $value) + $query->addMetaData($key, $value); + $count_query->addMetaData($key, $value); + } } if ($query) {