diff --git a/core/modules/views/lib/Drupal/views/DisplayBag.php b/core/modules/views/lib/Drupal/views/DisplayBag.php index 72023f3..8fc2fa7 100644 --- a/core/modules/views/lib/Drupal/views/DisplayBag.php +++ b/core/modules/views/lib/Drupal/views/DisplayBag.php @@ -7,6 +7,7 @@ namespace Drupal\views; +use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Component\Plugin\PluginBag; use Drupal\Component\Plugin\PluginManagerInterface; @@ -77,7 +78,17 @@ protected function initializePlugin($display_id) { // Retrieve and initialize the new display handler with data. $display = &$this->view->storage->getDisplay($display_id); - $this->pluginInstances[$display_id] = $this->manager->createInstance($display['display_plugin']); + + try { + $this->pluginInstances[$display_id] = $this->manager->createInstance($display['display_plugin']); + } + // Catch any plugin exceptions that are thrown. So we can fail nicely if a + // display plugin isn't found. + catch (PluginException $e) { + $message = $e->getMessage(); + watchdog('views', $message); + drupal_set_message(t('!message', array('!message' => $message)), 'warning'); + } 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. 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 4883ad5..ebaa975 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php @@ -19,7 +19,7 @@ class DisplayTest extends PluginTestBase { * * @var array */ - public static $testViews = array('test_filter_groups', 'test_get_attach_displays'); + public static $testViews = array('test_filter_groups', 'test_get_attach_displays', 'test_display_invalid'); /** * Modules to enable. @@ -141,4 +141,23 @@ public function testGetAttachedDisplays() { $this->assertEqual($view->display_handler->getAttachedDisplays(), array()); } + /** + * Tests an invalid display plugin. + */ + public function testInvalidDisplayPlugin() { + $this->drupalGet('test_display_invalid'); + $this->assertResponse(200); + + // Change the page plugin id to an invalid one. + $view = views_get_view('test_display_invalid'); + $displays = $view->storage->get('display'); + $displays['page_1']['display_plugin'] = 'invalid'; + $view->storage->set('display', $displays); + $view->save(); + + $this->drupalGet('test_display_invalid'); + $this->assertResponse(404); + $this->assertText(t('The plugin (invalid) did not specify an instance class.')); + } + }