Issue #2020387 by mr.baileys, Andi-D, dawehner, oadaeh, YesCT, Kars-T: Convert 'Active forum topics' block to a View.
parent
da4a1df3b7
commit
d166be3687
|
@ -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
|
|
@ -552,23 +552,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.
|
* Implements hook_preprocess_HOOK() for block templates.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -15,6 +15,7 @@ function forum_views_data() {
|
||||||
'field' => 'nid',
|
'field' => 'nid',
|
||||||
'title' => t('Forum content'),
|
'title' => t('Forum content'),
|
||||||
'access query tag' => 'node_access',
|
'access query tag' => 'node_access',
|
||||||
|
'query metadata' => array('base_table' => 'forum_index'),
|
||||||
);
|
);
|
||||||
|
|
||||||
$data['forum_index']['nid'] = array(
|
$data['forum_index']['nid'] = array(
|
||||||
|
|
|
@ -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'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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'];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -20,7 +20,7 @@ class ForumBlockTest extends WebTestBase {
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('forum', 'block');
|
public static $modules = array('forum', 'block', 'views');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A user with various administrative privileges.
|
* A user with various administrative privileges.
|
||||||
|
@ -59,7 +59,7 @@ class ForumBlockTest extends WebTestBase {
|
||||||
$topics = $this->createForumTopics();
|
$topics = $this->createForumTopics();
|
||||||
|
|
||||||
// Enable the new forum topics block.
|
// 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->drupalGet('');
|
||||||
|
|
||||||
$this->assertLink(t('More'), 0, 'New forum topics block has a "more"-link.');
|
$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) {
|
foreach ($topics as $topic) {
|
||||||
$this->assertLink($topic, 0, format_string('Forum topic @topic found in the "New forum topics" block.', array('@topic' => $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.
|
// Enable the block.
|
||||||
$block = $this->drupalPlaceBlock('forum_active_block');
|
$block = $this->drupalPlaceBlock('views_block:forum_topic_lists-block_1');
|
||||||
$this->drupalGet('');
|
$this->drupalGet('');
|
||||||
$this->assertLink(t('More'), 0, 'Active forum topics block has a "more"-link.');
|
$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.');
|
$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])));
|
$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.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -19,7 +19,7 @@ class ForumNodeAccessTest extends WebTestBase {
|
||||||
*
|
*
|
||||||
* @var array
|
* @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() {
|
public static function getInfo() {
|
||||||
return array(
|
return array(
|
||||||
|
@ -72,8 +72,8 @@ class ForumNodeAccessTest extends WebTestBase {
|
||||||
|
|
||||||
|
|
||||||
// Enable the new and active forum blocks.
|
// Enable the new and active forum blocks.
|
||||||
$this->drupalPlaceBlock('forum_active_block');
|
$this->drupalPlaceBlock('views_block:forum_topic_lists-block_1');
|
||||||
$this->drupalPlaceBlock('forum_new_block');
|
$this->drupalPlaceBlock('views_block:forum_topic_lists-block_2');
|
||||||
|
|
||||||
// Test for $access_user.
|
// Test for $access_user.
|
||||||
$this->drupalLogin($access_user);
|
$this->drupalLogin($access_user);
|
||||||
|
|
|
@ -1376,6 +1376,12 @@ class Sql extends QueryPluginBase {
|
||||||
$query->addTag($access_tag);
|
$query->addTag($access_tag);
|
||||||
$count_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) {
|
if ($query) {
|
||||||
|
|
Loading…
Reference in New Issue