Commit 3dcbc223 authored by alexpott's avatar alexpott

Issue #2272001 by dsnopek, Devin Carlson, tim.plunkett, xjm, martin107: Views...

Issue #2272001 by dsnopek, Devin Carlson, tim.plunkett, xjm, martin107: Views display plugin's list of handlers is not filtered by access
parent 42505613
...@@ -912,7 +912,7 @@ public function &getHandler($type, $id) { ...@@ -912,7 +912,7 @@ public function &getHandler($type, $id) {
* *
* @return \Drupal\views\Plugin\views\ViewsHandlerInterface[] * @return \Drupal\views\Plugin\views\ViewsHandlerInterface[]
*/ */
public function getHandlers($type) { public function &getHandlers($type) {
if (!isset($this->handlers[$type])) { if (!isset($this->handlers[$type])) {
$this->handlers[$type] = array(); $this->handlers[$type] = array();
$types = ViewExecutable::getHandlerTypes(); $types = ViewExecutable::getHandlerTypes();
......
...@@ -23,7 +23,7 @@ class AreaTest extends HandlerTestBase { ...@@ -23,7 +23,7 @@ class AreaTest extends HandlerTestBase {
* *
* @var array * @var array
*/ */
public static $testViews = array('test_example_area'); public static $testViews = array('test_example_area', 'test_example_area_access');
/** /**
* Modules to enable. * Modules to enable.
...@@ -112,6 +112,45 @@ public function testRenderArea() { ...@@ -112,6 +112,45 @@ public function testRenderArea() {
$this->assertTrue(strpos($output, $empty_string) !== FALSE); $this->assertTrue(strpos($output, $empty_string) !== FALSE);
} }
/**
* Tests the access for an area.
*/
public function testAreaAccess() {
// Test with access denied for the area handler.
$view = Views::getView('test_example_area_access');
$view->initDisplay();
$view->initHandlers();
$handlers = $view->display_handler->getHandlers('empty');
$this->assertEqual(0, count($handlers));
$output = $view->preview();
$output = \Drupal::service('renderer')->render($output);
// The area output should not be present since access was denied.
$this->assertFalse(strpos($output, 'a custom string') !== FALSE);
$view->destroy();
// Test with access granted for the area handler.
$view = Views::getView('test_example_area_access');
$view->initDisplay();
$view->display_handler->overrideOption('empty', [
'test_example' => [
'field' => 'test_example',
'id' => 'test_example',
'table' => 'views',
'plugin_id' => 'test_example',
'string' => 'a custom string',
'custom_access' => TRUE,
],
]);
$view->initHandlers();
$handlers = $view->display_handler->getHandlers('empty');
$output = $view->preview();
$output = \Drupal::service('renderer')->render($output);
$this->assertTrue(strpos($output, 'a custom string') !== FALSE);
$this->assertEqual(1, count($handlers));
}
/** /**
* Tests global tokens. * Tests global tokens.
*/ */
......
...@@ -886,7 +886,7 @@ protected function _postExecute() { ...@@ -886,7 +886,7 @@ protected function _postExecute() {
*/ */
protected function _initHandler($key, $info) { protected function _initHandler($key, $info) {
// Load the requested items from the display onto the object. // Load the requested items from the display onto the object.
$this->$key = $this->display_handler->getHandlers($key); $this->$key = &$this->display_handler->getHandlers($key);
// This reference deals with difficult PHP indirection. // This reference deals with difficult PHP indirection.
$handlers = &$this->$key; $handlers = &$this->$key;
......
# Schema for the views plugins of the Views test config module.
views.area.test_example:
type: views_area
label: 'Test example'
mapping:
string:
type: text
label: 'The shown text of the area'
custom_access:
type: boolean
label: 'Should access to the area be allowed'
langcode: und
status: true
dependencies: { }
id: test_example_area_access
module: views
description: ''
tag: ''
base_table: node
base_field: nid
core: '8'
display:
default:
display_options:
access:
type: none
cache:
type: none
empty:
test_example:
field: test_example
id: test_example
table: views
plugin_id: test_example
custom_access: false
string: 'a custom string'
display_plugin: default
display_title: Master
id: default
position: 0
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace Drupal\views_test_data\Plugin\views\area; namespace Drupal\views_test_data\Plugin\views\area;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\views\Plugin\views\area\AreaPluginBase; use Drupal\views\Plugin\views\area\AreaPluginBase;
/** /**
...@@ -19,12 +20,20 @@ ...@@ -19,12 +20,20 @@
*/ */
class TestExample extends AreaPluginBase { class TestExample extends AreaPluginBase {
/**
* {@inheritdoc}
*/
public function access(AccountInterface $account) {
return $this->options['custom_access'];
}
/** /**
* Overrides Drupal\views\Plugin\views\area\AreaPluginBase::option_definition(). * Overrides Drupal\views\Plugin\views\area\AreaPluginBase::option_definition().
*/ */
public function defineOptions() { public function defineOptions() {
$options = parent::defineOptions(); $options = parent::defineOptions();
$options['string'] = array('default' => ''); $options['string'] = array('default' => '');
$options['custom_access'] = array('default' => TRUE);
return $options; return $options;
} }
......
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