Commit 353315fc authored by webchick's avatar webchick

Issue #2151355 by damiankloip: Enable reset button on admin/content exposed filters.

parent f7e75db7
......@@ -18,7 +18,7 @@ display:
type: basic
options:
submit_button: Filter
reset_button: false
reset_button: true
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
......
This diff is collapsed.
<?php
/**
* @file
* Contains \Drupal\node\Plugin\Block\RecentContentBlock.
*/
namespace Drupal\node\Plugin\Block;
use Drupal\block\BlockBase;
use Drupal\block\Annotation\Block;
use Drupal\Core\Annotation\Translation;
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.'),
);
}
}
}
<?php
/**
* @file
* Definition of Drupal\node\Tests\NodeBlockFunctionalTest.
*/
namespace Drupal\node\Tests;
/**
* Functional tests for the node module blocks.
*/
class NodeBlockFunctionalTest extends NodeTestBase {
/**
* An administrative user for testing.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* An unprivileged user for testing.
*
* @var \Drupal\user\UserInterface
*/
protected $webUser;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('block');
public static function getInfo() {
return array(
'name' => 'Node blocks',
'description' => 'Test node block functionality.',
'group' => 'Node',
);
}
function setUp() {
parent::setUp();
// Create users and test node.
$this->adminUser = $this->drupalCreateUser(array('administer content types', 'administer nodes', 'administer blocks'));
$this->webUser = $this->drupalCreateUser(array('access content', 'create article content'));
}
/**
* Tests the recent comments block.
*/
public function testRecentNodeBlock() {
$this->drupalLogin($this->adminUser);
// Disallow anonymous users to view content.
user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
'access content' => FALSE,
));
// Enable the recent content block with two items.
$block = $this->drupalPlaceBlock('node_recent_block', array('id' => 'test_block', 'block_count' => 2));
// Test that block is not visible without nodes.
$this->drupalGet('');
$this->assertText(t('No content available.'), 'Block with "No content available." found.');
// Add some test nodes.
$default_settings = array('uid' => $this->webUser->id(), 'type' => 'article');
$node1 = $this->drupalCreateNode($default_settings);
$node2 = $this->drupalCreateNode($default_settings);
$node3 = $this->drupalCreateNode($default_settings);
// Change the changed time for node so that we can test ordering.
db_update('node_field_data')
->fields(array(
'changed' => $node1->getChangedTime() + 100,
))
->condition('nid', $node2->id())
->execute();
db_update('node_field_data')
->fields(array(
'changed' => $node1->getChangedTime() + 200,
))
->condition('nid', $node3->id())
->execute();
// Test that a user without the 'access content' permission cannot
// see the block.
$this->drupalLogout();
$this->drupalGet('');
$this->assertNoText($block->label(), 'Block was not found.');
// Test that only the 2 latest nodes are shown.
$this->drupalLogin($this->webUser);
$this->assertNoText($node1->label(), 'Node not found in block.');
$this->assertText($node2->label(), 'Node found in block.');
$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->drupalLogout();
$this->drupalLogin($this->adminUser);
// Set the number of recent nodes to show to 10.
$block->getPlugin()->setConfigurationValue('block_count', 10);
$block->save();
// Post an additional node.
$node4 = $this->drupalCreateNode($default_settings);
// drupalCreateNode() does not automatically flush content caches unlike
// posting a node from a node form.
cache_invalidate_tags(array('content' => TRUE));
// Test that all four nodes are shown.
$this->drupalGet('');
$this->assertText($node1->label(), 'Node found in block.');
$this->assertText($node2->label(), 'Node found in block.');
$this->assertText($node3->label(), 'Node found in block.');
$this->assertText($node4->label(), 'Node found in block.');
// Enable the "Powered by Drupal" block only on article nodes.
$block = $this->drupalPlaceBlock('system_powered_by_block', array(
'visibility' => array(
'node_type' => array(
'types' => array(
'article' => 'article',
),
),
),
));
$visibility = $block->get('visibility');
$this->assertTrue(isset($visibility['node_type']['types']['article']), 'Visibility settings were saved to configuration');
// Create a page node.
$node5 = $this->drupalCreateNode(array('uid' => $this->adminUser->id(), 'type' => 'page'));
// Verify visibility rules.
$this->drupalGet('');
$label = $block->label();
$this->assertNoText($label, 'Block was not displayed on the front page.');
$this->drupalGet('node/add/article');
$this->assertText($label, 'Block was displayed on the node/add/article page.');
$this->drupalGet('node/' . $node1->id());
$this->assertText($label, 'Block was displayed on the node/N when node is of type article.');
$this->drupalGet('node/' . $node5->id());
$this->assertNoText($label, 'Block was not displayed on nodes of type page.');
}
}
......@@ -162,12 +162,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',
......@@ -628,9 +622,6 @@ function node_preprocess_block(&$variables) {
case 'node_syndicate_block':
$variables['attributes']['role'] = 'complementary';
break;
case 'node_recent_block':
$variables['attributes']['role'] = 'navigation';
break;
}
}
}
......@@ -1137,94 +1128,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:
* - nodes: An array of recent node entities.
*
* @ingroup themeable
*/
function theme_node_recent_block($variables) {
$rows = array();
$output = '';
$l_options = array('query' => drupal_get_destination());
foreach ($variables['nodes'] as $node) {
$row = array();
$node_recent_content = array(
'#theme' => 'node_recent_content',
'#node' => $node,
);
$row[] = array(
'data' => drupal_render($node_recent_content),
'class' => 'title-author',
);
if ($node->access('update')) {
$row[] = array(
'data' => l(t('edit'), 'node/' . $node->id() . '/edit', $l_options),
'class' => 'edit',
);
}
if ($node->access('delete')) {
$row[] = array(
'data' => l(t('delete'), 'node/' . $node->id() . '/delete', $l_options),
'class' => 'delete',
);
}
$rows[] = $row;
}
if ($rows) {
$table = array(
'#theme' => 'table',
'#rows' => $rows,
);
$output = drupal_render($table);
if (user_access('access content overview')) {
$more_link = array(
'#theme' => 'more_link',
'#url' => 'admin/content',
'#title' => t('Show more content'),
);
$output .= drupal_render($more_link);
}
}
return $output;
}
/**
* Returns HTML for a recent node to be displayed in the recent content block.
*
* @param $variable
* An associative array containing:
* - node: A node entity.
*
* @ingroup themeable
*/
function theme_node_recent_content($variables) {
$node = $variables['node'];
$output = '<div class="node-title">';
$output .= l($node->label(), 'node/' . $node->id());
$mark = array(
'#theme' => 'mark',
'#status' => node_mark($node->id(), $node->getChangedTime()),
);
$output .= drupal_render($mark);
$output .= '</div><div class="node-author">';
$username = array(
'#theme' => 'username',
'#account' => $node->getAuthor(),
);
$output .= drupal_render($username);
$output .= '</div>';
return $output;
}
/**
* Implements hook_form_FORM_ID_alter() for block_form().
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment