diff --git a/core/modules/block/lib/Drupal/block/Tests/Views/DisplayBlockTest.php b/core/modules/block/lib/Drupal/block/Tests/Views/DisplayBlockTest.php index 5f3b776..050a1ea 100644 --- a/core/modules/block/lib/Drupal/block/Tests/Views/DisplayBlockTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/Views/DisplayBlockTest.php @@ -7,7 +7,6 @@ namespace Drupal\block\Tests\Views; -use Drupal\block\Plugin\Core\Entity\Block; use Drupal\views\Tests\ViewTestBase; use Drupal\views\Tests\ViewTestData; @@ -48,43 +47,6 @@ protected function setUp() { } /** - * Checks to see whether a block appears on the page. - * - * @param \Drupal\block\Plugin\Core\Entity\Block $block - * The block entity to find on the page. - */ - protected function assertBlockAppears(Block $block) { - $result = $this->findBlockInstance($block); - $this->assertTrue(!empty($result), format_string('Ensure the block @id appears on the page', array('@id' => $block->id()))); - } - - /** - * Checks to see whether a block does not appears on the page. - * - * @param \Drupal\block\Plugin\Core\Entity\Block $block - * The block entity to find on the page. - */ - protected function assertNoBlockAppears(Block $block) { - $result = $this->findBlockInstance($block); - $this->assertFalse(!empty($result), format_string('Ensure the block @id does not appear on the page', array('@id' => $block->id()))); - } - - /** - * Find a block instance on the page. - * - * @param \Drupal\block\Plugin\Core\Entity\Block $block - * The block entity to find on the page. - * - * @return array - * The result from the xpath query. - */ - protected function findBlockInstance(Block $block) { - $config_id = explode('.', $block->id()); - $machine_name = array_pop($config_id); - return $this->xpath('//div[@id = :id]', array(':id' => 'block-' . $machine_name)); - } - - /** * Tests removing a block display. */ protected function testDeleteBlockDisplay() { diff --git a/core/modules/views/lib/Drupal/views/DisplayBag.php b/core/modules/views/lib/Drupal/views/DisplayBag.php index 6e7a75b..fccdf72 100644 --- a/core/modules/views/lib/Drupal/views/DisplayBag.php +++ b/core/modules/views/lib/Drupal/views/DisplayBag.php @@ -60,7 +60,7 @@ public function __destruct() { * Overrides \Drupal\Component\Plugin\PluginBag::clear(). */ public function clear() { - foreach ($this->pluginInstances as $display_id => $display) { + foreach (array_filter($this->pluginInstances) as $display_id => $display) { $display->destroy(); } @@ -88,10 +88,10 @@ protected function initializePlugin($display_id) { $message = $e->getMessage(); drupal_set_message(t('!message', array('!message' => $message)), 'warning'); } + + // If no plugin instance has been created, return NULL. if (empty($this->pluginInstances[$display_id])) { - // Provide a 'default' handler as an emergency. This won't work well but - // it will keep things from crashing. - $this->pluginInstances[$display_id] = $this->manager->createInstance('default'); + return NULL; } $this->pluginInstances[$display_id]->initDisplay($this->view, $display); diff --git a/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsBlock.php b/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsBlock.php index 8a77f18..af7cfa7 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsBlock.php +++ b/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsBlock.php @@ -48,7 +48,6 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi list($name, $this->displayID) = explode('-', $delta, 2); // Load the view. $this->view = views_get_view($name); - $this->view->setDisplay($this->displayID); } /** @@ -74,15 +73,19 @@ public function form($form, &$form_state) { * Implements \Drupal\block\BlockBase::build(). */ public function build() { - $output = $this->view->executeDisplay($this->displayID); - // Set the label to the title configured in the view. - $this->entity->set('label', filter_xss_admin($this->view->getTitle())); - // Before returning the block output, convert it to a renderable array - // with contextual links. - $this->addContextualLinks($output); - - $this->view->destroy(); - return $output; + if ($output = $this->view->executeDisplay($this->displayID)) { + // Set the label to the title configured in the view. + $this->entity->set('label', filter_xss_admin($this->view->getTitle())); + // Before returning the block output, convert it to a renderable array + // with contextual links. + $this->addContextualLinks($output); + + $this->view->destroy(); + + return $output; + } + + return array(); } /** diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php index 8d6e2eb..77a1c4f 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php @@ -26,7 +26,7 @@ class DisplayTest extends PluginTestBase { * * @var array */ - public static $modules = array('views_ui', 'node'); + public static $modules = array('views_ui', 'node', 'block'); public static function getInfo() { return array( @@ -144,9 +144,9 @@ public function testGetAttachedDisplays() { } /** - * Tests an invalid display plugin. + * Tests invalid display plugins. */ - public function testInvalidDisplayPlugin() { + public function testInvalidDisplayPlugins() { $this->drupalGet('test_display_invalid'); $this->assertResponse(200); @@ -165,6 +165,30 @@ public function testInvalidDisplayPlugin() { $this->drupalGet('test_display_invalid'); $this->assertResponse(404); + + // Change the display plugin ID back to the correct ID. + $config = config('views.view.test_display_invalid'); + $config->set('display.page_1.display_plugin', 'page'); + $config->save(); + + // Place the block display. + $block = $this->drupalPlaceBlock('views_block:test_display_invalid-block_1', array(), array('title' => 'Invalid display')); + + $this->drupalGet(''); + $this->assertResponse(200); + $this->assertBlockAppears($block); + + // Change the block plugin ID to an invalid one. + $config = config('views.view.test_display_invalid'); + $config->set('display.block_1.display_plugin', 'invalid'); + $config->save(); + + // Test the page is still displayed, the block not present, and has the + // plugin warning message. + $this->drupalGet(''); + $this->assertResponse(200); + $this->assertText(t('The plugin (invalid) did not specify an instance class.')); + $this->assertNoBlockAppears($block); } } diff --git a/core/modules/views/lib/Drupal/views/Tests/ViewTestBase.php b/core/modules/views/lib/Drupal/views/Tests/ViewTestBase.php index 93685aa..0836300 100644 --- a/core/modules/views/lib/Drupal/views/Tests/ViewTestBase.php +++ b/core/modules/views/lib/Drupal/views/Tests/ViewTestBase.php @@ -8,6 +8,7 @@ namespace Drupal\views\Tests; use Drupal\simpletest\WebTestBase; +use Drupal\block\Plugin\Core\Entity\Block; /** * Defines a base class for Views testing in the full web test environment. @@ -224,6 +225,43 @@ protected function executeView($view, $args = array()) { } /** + * Checks to see whether a block appears on the page. + * + * @param \Drupal\block\Plugin\Core\Entity\Block $block + * The block entity to find on the page. + */ + protected function assertBlockAppears(Block $block) { + $result = $this->findBlockInstance($block); + $this->assertTrue(!empty($result), format_string('Ensure the block @id appears on the page', array('@id' => $block->id()))); + } + + /** + * Checks to see whether a block does not appears on the page. + * + * @param \Drupal\block\Plugin\Core\Entity\Block $block + * The block entity to find on the page. + */ + protected function assertNoBlockAppears(Block $block) { + $result = $this->findBlockInstance($block); + $this->assertFalse(!empty($result), format_string('Ensure the block @id does not appear on the page', array('@id' => $block->id()))); + } + + /** + * Find a block instance on the page. + * + * @param \Drupal\block\Plugin\Core\Entity\Block $block + * The block entity to find on the page. + * + * @return array + * The result from the xpath query. + */ + protected function findBlockInstance(Block $block) { + $config_id = explode('.', $block->id()); + $machine_name = array_pop($config_id); + return $this->xpath('//div[@id = :id]', array(':id' => 'block-' . $machine_name)); + } + + /** * Returns the schema definition. */ protected function schemaDefinition() { diff --git a/core/modules/views/lib/Drupal/views/ViewExecutable.php b/core/modules/views/lib/Drupal/views/ViewExecutable.php index 9a4ba48..11ae3ce 100644 --- a/core/modules/views/lib/Drupal/views/ViewExecutable.php +++ b/core/modules/views/lib/Drupal/views/ViewExecutable.php @@ -688,10 +688,13 @@ public function setDisplay($display_id = NULL) { $this->rowPlugin = NULL; } - // Set a shortcut. - $this->display_handler = $this->displayHandlers->get($display_id); + if ($display = $this->displayHandlers->get($display_id)) { + // Set a shortcut. + $this->display_handler = $display; + return TRUE; + } - return TRUE; + return FALSE; } /** @@ -1495,7 +1498,7 @@ public function access($displays = NULL, $account = NULL) { $displays = (array)$displays; foreach ($displays as $display_id) { if ($this->displayHandlers->has($display_id)) { - if ($this->displayHandlers->get($display_id)->access($account)) { + if (($display = $this->displayHandlers->get($display_id)) && $display->access($account)) { return TRUE; } } diff --git a/core/modules/views/tests/views_test_config/test_views/views.view.test_display_invalid.yml b/core/modules/views/tests/views_test_config/test_views/views.view.test_display_invalid.yml index 39a4c6d..7d13ccf 100644 --- a/core/modules/views/tests/views_test_config/test_views/views.view.test_display_invalid.yml +++ b/core/modules/views/tests/views_test_config/test_views/views.view.test_display_invalid.yml @@ -25,6 +25,11 @@ display: display_title: Page id: page_1 position: '0' + block_1: + display_plugin: block + id: block_1 + display_title: Block + position: '1' human_name: '' id: test_display_invalid tag: '' diff --git a/core/modules/views/views.module b/core/modules/views/views.module index 3bc0bd1..7ee7e72 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -445,10 +445,15 @@ function views_page($name, $display_id) { // Load the view and render it. if ($view = views_get_view($name)) { - return $view->executeDisplay($display_id, $args); + if ($output = $view->executeDisplay($display_id, $args)) { + return $output; + } + else { + return array(); + } } - // Fallback; if we get here no view was found or handler was not valid. + // Fallback if we get here no view was found. return MENU_NOT_FOUND; } diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php index a0f1016..7fcda31 100644 --- a/sites/default/default.settings.php +++ b/sites/default/default.settings.php @@ -444,14 +444,6 @@ # $settings['allow_authorize_operations'] = FALSE; /** - * Mixed-mode sessions: - * - * Set to TRUE to create both secure and insecure sessions when using HTTPS. - * Defaults to FALSE. - */ -# $settings['mixed_mode_sessions'] = TRUE; - -/** * Base URL (optional). * * If Drupal is generating incorrect URLs on your site, which could