summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2013-12-06 22:58:22 (GMT)
committerwebchick2013-12-06 22:58:22 (GMT)
commitd166be3687adcb3cd9c89114e917928c25509d9e (patch)
tree28fb282e475f47ad9151544678efeb492046ce3d
parentda4a1df3b747b52f342678e3865761e750b20824 (diff)
Issue #2020387 by mr.baileys, Andi-D, dawehner, oadaeh, YesCT, Kars-T: Convert 'Active forum topics' block to a View.
-rw-r--r--core/modules/forum/config/views.view.forum_topic_lists.yml229
-rw-r--r--core/modules/forum/forum.module17
-rw-r--r--core/modules/forum/forum.views.inc1
-rw-r--r--core/modules/forum/lib/Drupal/forum/Plugin/Block/ActiveTopicsBlock.php40
-rw-r--r--core/modules/forum/lib/Drupal/forum/Plugin/Block/ForumBlockBase.php58
-rw-r--r--core/modules/forum/lib/Drupal/forum/Plugin/Block/NewTopicsBlock.php40
-rw-r--r--core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php39
-rw-r--r--core/modules/forum/lib/Drupal/forum/Tests/ForumNodeAccessTest.php6
-rw-r--r--core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php6
9 files changed, 242 insertions, 194 deletions
diff --git a/core/modules/forum/config/views.view.forum_topic_lists.yml b/core/modules/forum/config/views.view.forum_topic_lists.yml
new file mode 100644
index 0000000..58826b7
--- /dev/null
+++ b/core/modules/forum/config/views.view.forum_topic_lists.yml
@@ -0,0 +1,229 @@
+base_table: forum_index
+core: 8.x
+description: 'A list of new or active forum topics'
+status: '1'
+display:
+ block_1:
+ display_plugin: block
+ id: block_1
+ display_title: 'Active forum topics'
+ position: '1'
+ display_options:
+ display_description: 'Displays a list of active forum topics'
+ sorts:
+ last_comment_timestamp:
+ id: last_comment_timestamp
+ table: forum_index
+ field: last_comment_timestamp
+ relationship: none
+ group_type: group
+ admin_label: ''
+ order: DESC
+ exposed: '0'
+ expose:
+ label: ''
+ granularity: second
+ plugin_id: date
+ defaults:
+ sorts: '0'
+ title: '0'
+ block_description: 'Active forum topics'
+ title: 'Active forum topics'
+ link_url: /forum
+ default:
+ display_plugin: default
+ id: default
+ display_title: Master
+ position: '1'
+ display_options:
+ access:
+ type: none
+ options: { }
+ cache:
+ type: none
+ options: { }
+ query:
+ type: views_query
+ options:
+ disable_sql_rewrite: '0'
+ distinct: '0'
+ slave: '0'
+ query_comment: ''
+ query_tags: { }
+ exposed_form:
+ type: basic
+ options:
+ submit_button: Apply
+ reset_button: '0'
+ reset_button_label: Reset
+ exposed_sorts_label: 'Sort by'
+ expose_sort_order: '1'
+ sort_asc_label: Asc
+ sort_desc_label: Desc
+ pager:
+ type: some
+ options:
+ items_per_page: '5'
+ offset: '0'
+ style:
+ type: html_list
+ options:
+ grouping: { }
+ row_class: ''
+ default_row_class: '1'
+ row_class_special: '1'
+ type: ul
+ wrapper_class: item-list
+ class: ''
+ row:
+ type: fields
+ fields:
+ nid:
+ id: nid
+ table: forum_index
+ field: nid
+ relationship: none
+ group_type: group
+ admin_label: ''
+ label: ''
+ exclude: '1'
+ alter:
+ alter_text: '0'
+ text: ''
+ make_link: '0'
+ path: ''
+ absolute: '0'
+ external: '0'
+ replace_spaces: '0'
+ path_case: none
+ trim_whitespace: '0'
+ alt: ''
+ rel: ''
+ link_class: ''
+ prefix: ''
+ suffix: ''
+ target: ''
+ nl2br: '0'
+ max_length: ''
+ word_boundary: '1'
+ ellipsis: '1'
+ more_link: '0'
+ more_link_text: ''
+ more_link_path: ''
+ strip_tags: '0'
+ trim: '0'
+ preserve_tags: ''
+ html: '0'
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: '0'
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: '1'
+ empty: ''
+ hide_empty: '0'
+ empty_zero: '0'
+ hide_alter_empty: '1'
+ set_precision: '0'
+ precision: '0'
+ decimal: .
+ separator: ','
+ format_plural: '0'
+ format_plural_singular: '1'
+ format_plural_plural: '@count'
+ prefix: ''
+ suffix: ''
+ title:
+ id: title
+ table: forum_index
+ field: title
+ relationship: none
+ group_type: group
+ admin_label: ''
+ label: ''
+ exclude: '0'
+ alter:
+ alter_text: '0'
+ text: ''
+ make_link: '1'
+ path: 'node/[nid]'
+ absolute: '0'
+ external: '0'
+ replace_spaces: '0'
+ path_case: none
+ trim_whitespace: '0'
+ alt: ''
+ rel: ''
+ link_class: ''
+ prefix: ''
+ suffix: ''
+ target: ''
+ nl2br: '0'
+ max_length: ''
+ word_boundary: '1'
+ ellipsis: '1'
+ more_link: '0'
+ more_link_text: ''
+ more_link_path: ''
+ strip_tags: '0'
+ trim: '0'
+ preserve_tags: ''
+ html: '0'
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: '0'
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: '1'
+ empty: ''
+ hide_empty: '0'
+ empty_zero: '0'
+ hide_alter_empty: '1'
+ plugin_id: standard
+ filters: { }
+ sorts: { }
+ title: 'New forum Topics'
+ header: { }
+ footer: { }
+ empty: { }
+ relationships: { }
+ arguments: { }
+ use_more: '1'
+ use_more_always: '1'
+ use_more_text: More
+ link_display: custom_url
+ block_2:
+ display_plugin: block
+ id: block_2
+ display_title: 'New forum topics'
+ position: '1'
+ display_options:
+ display_description: 'Displays a list of new forum topics'
+ sorts:
+ created:
+ id: created
+ table: forum_index
+ field: created
+ relationship: none
+ group_type: group
+ admin_label: ''
+ order: DESC
+ exposed: '0'
+ expose:
+ label: ''
+ granularity: second
+ plugin_id: date
+ defaults:
+ sorts: '0'
+ block_description: 'New forum topics'
+ link_url: /forum
+label: 'Forum Topic Lists'
+module: views
+id: forum_topic_lists
+tag: 'default'
+uuid: e9169074-fc80-4676-9708-8b0ef31c4c69
+langcode: en
diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module
index 95ebe76..92ea2a2 100644
--- a/core/modules/forum/forum.module
+++ b/core/modules/forum/forum.module
@@ -553,23 +553,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 templates.
*/
function forum_preprocess_block(&$variables) {
diff --git a/core/modules/forum/forum.views.inc b/core/modules/forum/forum.views.inc
index fa7174f..11b706f 100644
--- a/core/modules/forum/forum.views.inc
+++ b/core/modules/forum/forum.views.inc
@@ -15,6 +15,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 3c7aa2a..0000000
--- a/core/modules/forum/lib/Drupal/forum/Plugin/Block/ActiveTopicsBlock.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains \Drupal\forum\Plugin\Block\ActiveTopicsBlock.
- */
-
-namespace Drupal\forum\Plugin\Block;
-
-use Drupal\block\Annotation\Block;
-use Drupal\Core\Annotation\Translation;
-
-/**
- * Provides an 'Active forum topics' block.
- *
- * @Block(
- * id = "forum_active_block",
- * admin_label = @Translation("Active forum topics"),
- * category = @Translation("Lists (Views)")
- * )
- */
-class ActiveTopicsBlock extends ForumBlockBase {
-
- /**
- * {@inheritdoc}
- */
- public function build() {
- $query = db_select('forum_index', 'f')
- ->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/ForumBlockBase.php b/core/modules/forum/lib/Drupal/forum/Plugin/Block/ForumBlockBase.php
deleted file mode 100644
index c2ad994..0000000
--- a/core/modules/forum/lib/Drupal/forum/Plugin/Block/ForumBlockBase.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains \Drupal\forum\Plugin\Block\ForumBlockBase.
- */
-
-namespace Drupal\forum\Plugin\Block;
-
-use Drupal\block\BlockBase;
-use Drupal\Core\Session\AccountInterface;
-
-/**
- * Provides a base class for Forum blocks.
- */
-abstract class ForumBlockBase extends BlockBase {
-
- /**
- * {@inheritdoc}
- */
- public function defaultConfiguration() {
- return array(
- 'cache' => DRUPAL_CACHE_CUSTOM,
- 'properties' => array(
- 'administrative' => TRUE,
- ),
- 'block_count' => 5,
- );
- }
-
- /**
- * {@inheritdoc}
- */
- public function access(AccountInterface $account) {
- return $account->hasPermission('access content');
- }
-
- /**
- * Overrides \Drupal\block\BlockBase::blockForm().
- */
- public function blockForm($form, &$form_state) {
- $form['block_count'] = array(
- '#type' => 'select',
- '#title' => t('Number of topics'),
- '#default_value' => $this->configuration['block_count'],
- '#options' => drupal_map_assoc(range(2, 20)),
- );
- return $form;
- }
-
- /**
- * Overrides \Drupal\block\BlockBase::blockSubmit().
- */
- public function blockSubmit($form, &$form_state) {
- $this->configuration['block_count'] = $form_state['values']['block_count'];
- }
-
-}
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 43c0442..0000000
--- a/core/modules/forum/lib/Drupal/forum/Plugin/Block/NewTopicsBlock.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains \Drupal\forum\Plugin\Block\NewTopicsBlock.
- */
-
-namespace Drupal\forum\Plugin\Block;
-
-use Drupal\block\Annotation\Block;
-use Drupal\Core\Annotation\Translation;
-
-/**
- * Provides a 'New forum topics' block.
- *
- * @Block(
- * id = "forum_new_block",
- * admin_label = @Translation("New forum topics"),
- * category = @Translation("Lists (Views)")
- * )
- */
-class NewTopicsBlock extends ForumBlockBase {
-
- /**
- * {@inheritdoc}
- */
- public function build() {
- $query = db_select('forum_index', 'f')
- ->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 ab8feb9..1bb4509 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 @@ class ForumBlockTest extends WebTestBase {
$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 @@ class ForumBlockTest extends WebTestBase {
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])));
- }
- }
}
/**
@@ -115,7 +99,7 @@ class ForumBlockTest extends WebTestBase {
}
// 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.');
@@ -131,23 +115,6 @@ class ForumBlockTest extends WebTestBase {
$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 99f8b25..146c69f 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 @@ class ForumNodeAccessTest extends WebTestBase {
// 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 820ec66..a664fab 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 @@ class Sql extends QueryPluginBase {
$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) {