diff --git a/core/lib/Drupal/Core/Ajax/AjaxResponse.php b/core/lib/Drupal/Core/Ajax/AjaxResponse.php index 97eca0a..1a3b5fa 100644 --- a/core/lib/Drupal/Core/Ajax/AjaxResponse.php +++ b/core/lib/Drupal/Core/Ajax/AjaxResponse.php @@ -39,37 +39,6 @@ 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 @@ -110,7 +79,7 @@ public function addCommand(CommandInterface $command, $prepend = FALSE) { 'library' => $assets->getLibraries(), 'drupalSettings' => $assets->getSettings(), ]; - $attachments = $this->renderer->mergeAttachments($this->attachments, $attachments); + $attachments = $this->getRenderer()->mergeAttachments($this->attachments, $attachments); $this->setAttachments($attachments); } @@ -260,4 +229,14 @@ protected function ajaxRender(Request $request) { return $commands; } + /** + * The renderer service. + * + * @return \Drupal\Core\Render\Renderer + * Service that turns a render array into a HTML string. + */ + public function getRenderer() { + return \Drupal::service('renderer'); + } + }