diff --git a/core/lib/Drupal/Core/Ajax/AjaxResponse.php b/core/lib/Drupal/Core/Ajax/AjaxResponse.php index a28017d..97eca0a 100644 --- a/core/lib/Drupal/Core/Ajax/AjaxResponse.php +++ b/core/lib/Drupal/Core/Ajax/AjaxResponse.php @@ -7,9 +7,9 @@ namespace Drupal\Core\Ajax; -use Drupal\Component\Utility\NestedArray; use Drupal\Core\Asset\AttachedAssets; use Drupal\Core\Render\Renderer; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -39,6 +39,37 @@ class AjaxResponse extends JsonResponse { ]; /** + * The renderer service. + * + * @var \Drupal\Core\Render\Renderer + */ + protected $renderer; + + /** + * Constructs a new AjaxResponse object. + * + * @param \Drupal\Core\Render\Renderer $renderer + * The renderer service. + * @param mixed $data + * The response data. + * @param int $status + * The response status code. + * @param array $headers + * An array of response headers. + */ + public function __construct(Renderer $renderer, $data = NULL, $status = 200, $headers = array()) { + parent::__construct($data, $status, $headers); + $this->renderer = $renderer; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, $data = NULL, $status = 200, $headers = array()) { + return new static($container->get('renderer'), $data, $status, $headers); + } + + /** * Sets attachments for this Ajax response. * * When this Ajax response is rendered, it will take care of generating the @@ -79,7 +110,7 @@ public function addCommand(CommandInterface $command, $prepend = FALSE) { 'library' => $assets->getLibraries(), 'drupalSettings' => $assets->getSettings(), ]; - $attachments = NestedArray::mergeDeep($this->attachments, $attachments); + $attachments = $this->renderer->mergeAttachments($this->attachments, $attachments); $this->setAttachments($attachments); }