Unverified Commit a4cf7243 authored by larowlan's avatar larowlan
Browse files

Issue #2868258 by joegraduate, Lendude, Jons, dawehner, alexpott, larowlan:...

Issue #2868258 by joegraduate, Lendude, Jons, dawehner, alexpott, larowlan: Missing View not helpfully reported in preRenderViewElement()

(cherry picked from commit 1ab0f484)
parent 220c6c9e
......@@ -3,6 +3,7 @@
namespace Drupal\views\Element;
use Drupal\Core\Render\Element\RenderElement;
use Drupal\views\Exception\ViewRenderElementException;
use Drupal\views\Views;
/**
......@@ -41,6 +42,9 @@ public static function preRenderViewElement($element) {
if (!isset($element['#view'])) {
$view = Views::getView($element['#name']);
if (!$view) {
throw new ViewRenderElementException("Invalid View name ({$element['#name']}) given.");
}
}
else {
$view = $element['#view'];
......
<?php
namespace Drupal\views\Exception;
/**
* Defines an exception for an invalid View render element.
*/
class ViewRenderElementException extends \Exception {}
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\views\Kernel;
use Drupal\views\Exception\ViewRenderElementException;
use Drupal\views\Views;
/**
......@@ -129,4 +130,19 @@ public function testViewElementEmbed() {
$this->assertCount(1, $this->xpath('//form[@class="views-exposed-form"]'));
}
/**
* Tests that an exception is thrown when an invalid View is passed.
*/
public function testInvalidView() {
$renderer = $this->container->get('renderer');
$render_element = [
'#type' => 'view',
'#name' => 'invalid_view_name',
'#embed' => FALSE,
];
$this->expectException(ViewRenderElementException::class);
$this->expectExceptionMessage("Invalid View name ({$render_element['#name']}) given.");
$renderer->renderRoot($render_element);
}
}
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