Commit 3c7bc9f9 authored by catch's avatar catch

Issue #3065629 by Charlie ChX Negyesi: Empty AJAX replies die with a mysterious exception

parent 84df3bb3
......@@ -30,6 +30,9 @@ trait CommandWithAttachedAssetsTrait {
protected function getRenderedContent() {
$this->attachedAssets = new AttachedAssets();
if (is_array($this->content)) {
if (!$this->content) {
return '';
}
$html = \Drupal::service('renderer')->renderRoot($this->content);
$this->attachedAssets = AttachedAssets::createFromRenderArray($this->content);
return $html;
......
......@@ -3,6 +3,7 @@
namespace Drupal\KernelTests\Core\Ajax;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\InsertCommand;
use Drupal\Core\EventSubscriber\AjaxResponseSubscriber;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\HttpFoundation\Request;
......@@ -56,6 +57,15 @@ public function testAttachedSettings() {
$assert('Settings command exists when JS aggregation is enabled.');
}
/**
* Checks empty content in commands does not throw exceptions.
*
* @doesNotPerformAssertions
*/
public function testEmptyInsertCommand() {
(new InsertCommand('foobar', []))->render();
}
/**
* Asserts the array of Ajax commands contains the searched command.
*
......
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