Unverified Commit b5241ea9 authored by alexpott's avatar alexpott
Browse files

Revert "Issue #3143096 by jedihe, jyotimishra123, shetpooja04, alexpott,...

Revert "Issue #3143096 by jedihe, jyotimishra123, shetpooja04, alexpott, mradcliffe: [DX]: throw an exception if #lazy_builder callback does not return a (renderable) array"

This reverts commit eebe8645.
parent eebe8645
...@@ -353,23 +353,6 @@ protected function doRender(&$elements, $is_root_call = FALSE) { ...@@ -353,23 +353,6 @@ protected function doRender(&$elements, $is_root_call = FALSE) {
// Build the element if it is still empty. // Build the element if it is still empty.
if (isset($elements['#lazy_builder'])) { if (isset($elements['#lazy_builder'])) {
$new_elements = $this->doCallback('#lazy_builder', $elements['#lazy_builder'][0], $elements['#lazy_builder'][1]); $new_elements = $this->doCallback('#lazy_builder', $elements['#lazy_builder'][0], $elements['#lazy_builder'][1]);
// Throw an exception if #lazy_builder callback does not return an array;
// provide helpful details for troubleshooting.
if (!is_array($new_elements)) {
$callable = $elements['#lazy_builder'][0];
$callable_name = '[unknown]';
if ($callable instanceof \Closure) {
$callable_name = '[closure]';
}
elseif (is_array($callable)) {
$callable_name = implode('::', $callable);
}
elseif (is_string($callable)) {
$callable_name = $callable;
}
$wrong_type = gettype($new_elements);
throw new \LogicException("#lazy_builder callbacks must return a valid renderable array, got $wrong_type from $callable_name");
}
// Retain the original cacheability metadata, plus cache keys. // Retain the original cacheability metadata, plus cache keys.
CacheableMetadata::createFromRenderArray($elements) CacheableMetadata::createFromRenderArray($elements)
->merge(CacheableMetadata::createFromRenderArray($new_elements)) ->merge(CacheableMetadata::createFromRenderArray($new_elements))
......
...@@ -962,54 +962,6 @@ public function testCreatePlaceholderPropertyWithoutLazyBuilder() { ...@@ -962,54 +962,6 @@ public function testCreatePlaceholderPropertyWithoutLazyBuilder() {
$this->renderer->renderRoot($element); $this->renderer->renderRoot($element);
} }
/**
* Tests lazy builders (string callable) that do not return a renderable.
*
* @covers ::render
* @covers ::doRender
*/
public function testNonArrayReturnFromLazyBuilderStringCallable() {
$element = [];
$element['#lazy_builder'] = ['Drupal\Tests\Core\Render\PlaceholdersTest::callbackNonArrayReturn', []];
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('#lazy_builder callbacks must return a valid renderable array, got boolean from Drupal\Tests\Core\Render\PlaceholdersTest::callbackNonArrayReturn');
$this->renderer->renderRoot($element);
}
/**
* Tests lazy builders (array callable) that do not return a renderable.
*
* @covers ::render
* @covers ::doRender
*/
public function testNonArrayReturnFromLazyBuilderArrayCallable() {
$element = [];
$element['#lazy_builder'] = [['Drupal\Tests\Core\Render\PlaceholdersTest', 'callbackNonArrayReturn'], []];
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('#lazy_builder callbacks must return a valid renderable array, got boolean from Drupal\Tests\Core\Render\PlaceholdersTest::callbackNonArrayReturn');
$this->renderer->renderRoot($element);
}
/**
* Tests lazy builders (closure) that do not return a renderable.
*
* @covers ::render
* @covers ::doRender
*/
public function testNonArrayReturnFromLazyBuilderClosure() {
$element = [];
$closure = function () {
return NULL;
};
$element['#lazy_builder'] = [$closure, []];
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('#lazy_builder callbacks must return a valid renderable array, got NULL from [closure]');
$this->renderer->renderRoot($element);
}
/** /**
* Create an element with a child and subchild. Each element has the same * Create an element with a child and subchild. Each element has the same
* #lazy_builder callback, but with different contexts. They don't modify * #lazy_builder callback, but with different contexts. They don't modify
......
...@@ -317,21 +317,11 @@ public static function callbackTagCurrentTemperature($animal) { ...@@ -317,21 +317,11 @@ public static function callbackTagCurrentTemperature($animal) {
return $build; return $build;
} }
/**
* Returns invalid renderable to #lazy_builder callback.
*
* @return bool
* TRUE.
*/
public static function callbackNonArrayReturn() {
return TRUE;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function trustedCallbacks() { public static function trustedCallbacks() {
return ['callbackTagCurrentTemperature', 'callbackPerUser', 'callback', 'callbackNonArrayReturn']; return ['callbackTagCurrentTemperature', 'callbackPerUser', 'callback'];
} }
} }
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