Commit 1415f2ad authored by webchick's avatar webchick

Issue #2020393 by dawehner, bdone, pcambra, oadaeh: Convert "Recent content" block to a View.

parent 672295bb
base_field: nid
base_table: node
core: 8.x
description: 'Recent content.'
status: 1
display:
block_1:
display_plugin: block
id: block_1
display_title: Block
position: '1'
block_category: 'Lists (Views)'
display_options:
link_url: admin/content
default:
display_plugin: default
id: default
display_title: Master
position: '1'
display_options:
access:
type: perm
options:
perm: 'access content'
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: '10'
offset: '0'
style:
type: table
options:
grouping: { }
row_class: ''
default_row_class: '1'
row_class_special: '1'
override: '1'
sticky: '0'
caption: ''
summary: ''
description: ''
columns:
title: title
timestamp: title
name: title
edit_node: edit_node
delete_node: delete_node
info:
title:
sortable: '0'
default_sort_order: asc
align: ''
separator: ''
empty_column: '0'
responsive: ''
timestamp:
sortable: '0'
default_sort_order: asc
align: ''
separator: ''
empty_column: '0'
responsive: ''
name:
sortable: '0'
default_sort_order: asc
align: ''
separator: ''
empty_column: '0'
responsive: ''
edit_node:
sortable: '0'
default_sort_order: asc
align: ''
separator: ''
empty_column: '1'
responsive: ''
delete_node:
sortable: '0'
default_sort_order: asc
align: ''
separator: ''
empty_column: '1'
responsive: ''
default: '-1'
empty_table: '0'
row:
type: fields
fields:
title:
id: title
table: node_field_data
field: title
relationship: none
group_type: group
admin_label: ''
label: ''
exclude: '0'
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: '0'
ellipsis: '0'
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'
link_to_node: '1'
provider: node
timestamp:
id: timestamp
table: history
field: timestamp
relationship: none
group_type: group
admin_label: ''
label: ''
exclude: '0'
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'
link_to_node: '0'
comments: '0'
plugin_id: history_user_timestamp
provider: history
name:
id: name
table: users
field: name
relationship: uid
group_type: group
admin_label: ''
label: ''
exclude: '0'
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: div
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'
link_to_user: '1'
overwrite_anonymous: '0'
anonymous_text: ''
format_username: '1'
plugin_id: user_name
provider: user
edit_node:
id: edit_node
table: node
field: edit_node
relationship: none
group_type: group
admin_label: ''
label: ''
exclude: '0'
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'
text: edit
plugin_id: node_link_edit
provider: node
delete_node:
id: delete_node
table: node
field: delete_node
relationship: none
group_type: group
admin_label: ''
label: ''
exclude: '0'
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'
text: delete
plugin_id: node_link_delete
provider: node
filters:
status_extra:
id: status_extra
table: node_field_data
field: status_extra
relationship: none
group_type: group
admin_label: ''
operator: '='
value: ''
group: '1'
exposed: '0'
expose:
operator_id: '0'
label: ''
description: ''
use_operator: '0'
operator: ''
identifier: ''
required: '0'
remember: '0'
multiple: '0'
remember_roles:
authenticated: authenticated
is_grouped: '0'
group_info:
label: ''
description: ''
identifier: ''
optional: '1'
widget: select
multiple: '0'
remember: '0'
default_group: All
default_group_multiple: { }
group_items: { }
plugin_id: node_status
provider: node
sorts:
changed:
id: changed
table: node_field_data
field: changed
relationship: none
group_type: group
admin_label: ''
order: DESC
exposed: '0'
expose:
label: ''
granularity: second
plugin_id: date
provider: views
title: 'Recent content'
header: { }
footer: { }
empty:
area_text_custom:
id: area_text_custom
table: views
field: area_text_custom
relationship: none
group_type: group
admin_label: ''
empty: '1'
tokenize: '0'
content: 'No content available.'
plugin_id: text_custom
provider: views
relationships:
uid:
id: uid
table: node_field_data
field: uid
relationship: none
group_type: group
admin_label: author
required: '1'
plugin_id: standard
provider: views
arguments: { }
filter_groups:
operator: AND
groups: { }
use_more: '1'
use_more_always: '1'
use_more_text: More
link_display: custom_url
label: 'Recent content'
module: views
id: content_recent
tag: default
uuid: 22208367-bde8-4977-ae04-4f1a34383ae3
langcode: en
<?php
/**
* @file
* Contains \Drupal\node\Plugin\Block\RecentContentBlock.
*/
namespace Drupal\node\Plugin\Block;
use Drupal\block\BlockBase;
use Drupal\Core\Session\AccountInterface;
/**
* Provides a 'Recent content' block.
*
* @Block(
* id = "node_recent_block",
* admin_label = @Translation("Recent content"),
* category = @Translation("Lists (Views)")
* )
*/
class RecentContentBlock extends BlockBase {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return array(
'block_count' => 10,
);
}
/**
* {@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 recent content items to display'),
'#default_value' => $this->configuration['block_count'],
'#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 30)),
);
return $form;
}
/**
* Overrides \Drupal\block\BlockBase::blockSubmit().
*/
public function blockSubmit($form, &$form_state) {
$this->configuration['block_count'] = $form_state['values']['block_count'];
}
/**
* {@inheritdoc}
*/
public function build() {
if ($nodes = node_get_recent($this->configuration['block_count'])) {
return array(
'#theme' => 'node_recent_block',
'#nodes' => $nodes,
);
}
else {
return array(
'#children' => t('No content available.'),
);
}
}
}
......@@ -31,7 +31,7 @@ class NodeBlockFunctionalTest extends NodeTestBase {
*
* @var array
*/
public static $modules = array('block');
public static $modules = array('block', 'views');
public static function getInfo() {
return array(
......@@ -61,7 +61,7 @@ public function testRecentNodeBlock() {
));
// Enable the recent content block with two items.
$block = $this->drupalPlaceBlock('node_recent_block', array('id' => 'test_block', 'block_count' => 2));
$block = $this->drupalPlaceBlock('views_block:content_recent-block_1', array('id' => 'test_block', 'items_per_page' => 2));
// Test that block is not visible without nodes.
$this->drupalGet('');
......@@ -100,13 +100,13 @@ public function testRecentNodeBlock() {
$this->assertText($node3->label(), 'Node found in block.');
// Check to make sure nodes are in the right order.
$this->assertTrue($this->xpath('//div[@id="block-test-block"]/div/table/tbody/tr[position() = 1]/td/div/a[text() = "' . $node3->label() . '"]'), 'Nodes were ordered correctly in block.');
$this->assertTrue($this->xpath('//div[@id="block-test-block"]//table/tbody/tr[position() = 1]/td/a[text() = "' . $node3->label() . '"]'), 'Nodes were ordered correctly in block.');
$this->drupalLogout();
$this->drupalLogin($this->adminUser);
// Set the number of recent nodes to show to 10.
$block->getPlugin()->setConfigurationValue('block_count', 10);
$block->getPlugin()->setConfigurationValue('items_per_page', 10);
$block->save();
// Post an additional node.
......
......@@ -160,12 +160,6 @@ function node_theme() {
'variables' => array('node' => NULL),
'file' => 'node.pages.inc',
),
'node_recent_block' => array(
'variables' => array('nodes' => NULL),
),
'node_recent_content' => array(
'variables' => array('node' => NULL),
),
'node_edit_form' => array(
'render element' => 'form',
'template' => 'node-edit-form',
......@@ -606,9 +600,6 @@ function node_preprocess_block(&$variables) {
case 'node_syndicate_block':
$variables['attributes']['role'] = 'complementary';
break;
case 'node_recent_block':
$variables['attributes']['role'] = 'navigation';
break;
}
}
}
......@@ -1097,94 +1088,6 @@ function node_get_recent($number = 10) {
return $nodes ? $nodes : array();
}
/**
* Returns HTML for a list of recent content.
*
* @param $variables
* An associative array containing: