diff --git a/core/modules/views/lib/Drupal/views/DisplayBag.php b/core/modules/views/lib/Drupal/views/DisplayBag.php index b6b9db9..e91ed74 100644 --- a/core/modules/views/lib/Drupal/views/DisplayBag.php +++ b/core/modules/views/lib/Drupal/views/DisplayBag.php @@ -8,6 +8,7 @@ namespace Drupal\views; use Drupal\Component\Plugin\PluginBag; +use Drupal\Component\Plugin\Exception\PluginException; /** * A class which wraps the displays of a view so you can lazy-initialize them. @@ -66,7 +67,18 @@ 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] = drupal_container()->get("plugin.manager.views.display")->createInstance($display['display_plugin']); + + try { + $this->pluginInstances[$display_id] = drupal_container()->get("plugin.manager.views.display")->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 cd476c8..22abf09 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.')); + } + } 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 new file mode 100644 index 0000000..6c7b10c --- /dev/null +++ b/core/modules/views/tests/views_test_config/test_views/views.view.test_display_invalid.yml @@ -0,0 +1,29 @@ +api_version: '3.0' +base_table: views_test_data +core: '8' +description: '' +disabled: '0' +display: + default: + display_options: + row: + type: fields + fields: + id: + id: id + table: views_test_data + field: id + display_plugin: default + display_title: Master + id: default + position: '0' + page_1: + display_options: + path: test_display_invalid + display_plugin: page + display_title: Page + id: page_1 + position: '0' +human_name: '' +name: test_display_invalid +tag: ''