Commit a0078c51 authored by alexpott's avatar alexpott

Issue #2460695 by mitrpaka, rpayanm: No methods on RendererInterface should be static

parent 7f90ee63
......@@ -657,7 +657,7 @@ function drupal_js_defaults($data = NULL) {
* \Drupal\Core\Render\Renderer::mergeAttachments() instead.
*/
function drupal_merge_attached(array $a, array $b) {
return Renderer::mergeAttachments($a, $b);
return \Drupal::service('renderer')->mergeAttachments($a, $b);
}
/**
......
......@@ -9,6 +9,7 @@
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;
......@@ -78,7 +79,7 @@ public function addCommand(CommandInterface $command, $prepend = FALSE) {
'library' => $assets->getLibraries(),
'drupalSettings' => $assets->getSettings(),
];
$attachments = Renderer::mergeAttachments($this->attachments, $attachments);
$attachments = $this->getRenderer()->mergeAttachments($this->attachments, $attachments);
$this->setAttachments($attachments);
}
......@@ -193,7 +194,7 @@ protected function ajaxRender(Request $request) {
// Prepend commands to add the assets, preserving their relative order.
$resource_commands = array();
$renderer = \Drupal::service('renderer');
$renderer = $this->getRenderer();
if (!empty($css_assets)) {
$css_render_array = \Drupal::service('asset.css.collection_renderer')->render($css_assets);
$resource_commands[] = new AddCssCommand($renderer->render($css_render_array));
......@@ -228,4 +229,14 @@ protected function ajaxRender(Request $request) {
return $commands;
}
/**
* The renderer service.
*
* @return \Drupal\Core\Render\Renderer
* The renderer service.
*/
protected function getRenderer() {
return \Drupal::service('renderer');
}
}
......@@ -71,7 +71,7 @@ public function merge(BubbleableMetadata $other) {
$result->contexts = Cache::mergeContexts($this->contexts, $other->contexts);
$result->tags = Cache::mergeTags($this->tags, $other->tags);
$result->maxAge = Cache::mergeMaxAges($this->maxAge, $other->maxAge);
$result->attached = Renderer::mergeAttachments($this->attached, $other->attached);
$result->attached = \Drupal::service('renderer')->mergeAttachments($this->attached, $other->attached);
$result->postRenderCache = NestedArray::mergeDeep($this->postRenderCache, $other->postRenderCache);
return $result;
}
......
......@@ -286,7 +286,7 @@ public function invokePageAttachmentHooks(array &$page) {
}
// Merge the attachments onto the $page render array.
$page = Renderer::mergeBubbleableMetadata($page, $attachments);
$page = $this->renderer->mergeBubbleableMetadata($page, $attachments);
}
/**
......
......@@ -782,7 +782,7 @@ public function getCacheableRenderArray(array $elements) {
/**
* {@inheritdoc}
*/
public static function mergeBubbleableMetadata(array $a, array $b) {
public function mergeBubbleableMetadata(array $a, array $b) {
$meta_a = BubbleableMetadata::createFromRenderArray($a);
$meta_b = BubbleableMetadata::createFromRenderArray($b);
$meta_a->merge($meta_b)->applyTo($a);
......@@ -801,7 +801,7 @@ public function addDependency(array &$elements, $dependency) {
/**
* {@inheritdoc}
*/
public static function mergeAttachments(array $a, array $b) {
public function mergeAttachments(array $a, array $b) {
// If both #attached arrays contain drupalSettings, then merge them
// correctly; adding the same settings multiple times needs to behave
// idempotently.
......
......@@ -340,7 +340,7 @@ public function getCacheableRenderArray(array $elements);
*
* @see \Drupal\Core\Render\BubbleableMetadata
*/
public static function mergeBubbleableMetadata(array $a, array $b);
public function mergeBubbleableMetadata(array $a, array $b);
/**
* Adds a dependency on an object: merges its cacheability metadata.
......@@ -398,7 +398,7 @@ public function addDependency(array &$elements, $dependency);
* @return array
* The merged attachments array.
*/
public static function mergeAttachments(array $a, array $b);
public function mergeAttachments(array $a, array $b);
/**
* Generates a render cache placeholder.
......
......@@ -121,7 +121,7 @@ public function renderForm(array $element, array $context) {
$callback = 'comment.post_render_cache:renderForm';
$placeholder = $this->generatePlaceholder($callback, $context);
$element['#markup'] = str_replace($placeholder, $markup, $element['#markup']);
$element = Renderer::mergeBubbleableMetadata($element, $form);
$element = $this->renderer->mergeBubbleableMetadata($element, $form);
return $element;
}
......
......@@ -11,7 +11,7 @@
use Drupal\views\Ajax\ViewAjaxResponse;
use Drupal\views\Controller\ViewAjaxController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* @coversDefaultClass \Drupal\views\Controller\ViewAjaxController
......@@ -61,6 +61,9 @@ class ViewAjaxControllerTest extends UnitTestCase {
*/
protected $renderer;
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->viewStorage = $this->getMock('Drupal\Core\Entity\EntityStorageInterface');
$this->executableFactory = $this->getMockBuilder('Drupal\views\ViewExecutableFactory')
......@@ -79,6 +82,14 @@ protected function setUp() {
$this->redirectDestination = $this->getMock('\Drupal\Core\Routing\RedirectDestinationInterface');
$this->viewAjaxController = new ViewAjaxController($this->viewStorage, $this->executableFactory, $this->renderer, $this->currentPath, $this->redirectDestination);
$this->renderer = $this->getMockBuilder('Drupal\Core\Render\Renderer')
->disableOriginalConstructor()
->setMethods(NULL)
->getMock();
$container = new ContainerBuilder();
$container->set('renderer', $this->renderer);
\Drupal::setContainer($container);
}
/**
......
......@@ -10,6 +10,7 @@
use Drupal\Core\Render\MainContent\AjaxRenderer;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* @coversDefaultClass \Drupal\Core\Render\MainContent\AjaxRenderer
......@@ -24,6 +25,13 @@ class AjaxRendererTest extends UnitTestCase {
*/
protected $ajaxRenderer;
/**
* The renderer.
*
* @var \Drupal\Core\Render\RendererInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $renderer;
/**
* {@inheritdoc}
*/
......@@ -38,6 +46,14 @@ protected function setUp() {
'#error' => NULL,
]);
$this->ajaxRenderer = new TestAjaxRenderer($element_info_manager);
$this->renderer = $this->getMockBuilder('Drupal\Core\Render\Renderer')
->disableOriginalConstructor()
->setMethods(NULL)
->getMock();
$container = new ContainerBuilder();
$container->set('renderer', $this->renderer);
\Drupal::setContainer($container);
}
/**
......
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