diff -u b/core/modules/views/src/ViewExecutable.php b/core/modules/views/src/ViewExecutable.php --- b/core/modules/views/src/ViewExecutable.php +++ b/core/modules/views/src/ViewExecutable.php @@ -769,6 +769,9 @@ * * @return bool * TRUE if the display was correctly set, FALSE otherwise. + * + * @throws \Drupal\views\InvalidDisplayException + * Thrown when an invalid display ID is passed. */ public function setDisplay($display_id = NULL) { // If we have not already initialized the display, do so. @@ -788,8 +791,7 @@ // Ensure the requested display exists. if (!$this->displayHandlers->has($display_id)) { - debug(format_string('setDisplay() called with invalid display ID "@display".', ['@display' => $display_id])); - return FALSE; + throw new InvalidDisplayException("ViewExecutable::setDisplay called with invalid display ID: $display_id"); } // Reset if the display has changed. It could be called multiple times for @@ -799,7 +801,7 @@ // Ensure the requested display exists. if (!$this->displayHandlers->has($display_id)) { - trigger_error(new FormattableMarkup('setDisplay() called with invalid display ID "@display".', ['@display' => $display_id])); + debug(format_string('setDisplay() called with invalid display ID "@display".', ['@display' => $display_id])); return FALSE; } diff -u b/core/modules/views/tests/src/Kernel/ViewExecutableTest.php b/core/modules/views/tests/src/Kernel/ViewExecutableTest.php --- b/core/modules/views/tests/src/Kernel/ViewExecutableTest.php +++ b/core/modules/views/tests/src/Kernel/ViewExecutableTest.php @@ -6,6 +6,7 @@ use Drupal\Component\Utility\Xss; use Drupal\node\Entity\NodeType; use Drupal\views\Entity\View; +use Drupal\views\InvalidDisplayException; use Drupal\views\Views; use Drupal\views\ViewExecutable; use Drupal\views\ViewExecutableFactory; @@ -199,8 +200,8 @@ try { $view->setDisplay('invalid'); } - catch (\PHPUnit_Framework_Error $e) { - $this->assertEquals('setDisplay() called with invalid display ID "invalid".', $e->getMessage()); + catch (InvalidDisplayException $e) { + $this->assertEquals('ViewExecutable::setDisplay called with invalid display ID: invalid', $e->getMessage()); } $this->assertEqual($view->current_display, 'default', 'If setDisplay is called with an invalid display id the default display should be used.'); only in patch2: unchanged: --- /dev/null +++ b/core/modules/views/src/InvalidDisplayException.php @@ -0,0 +1,10 @@ +