Commit 8d848f2d authored by xjm's avatar xjm

Issue #2505669 by pwolanin, jcloys, joshi.rohit100: Inject render service into...

Issue #2505669 by pwolanin, jcloys, joshi.rohit100: Inject render service into LinkGenerator instead of calling drupal_render
parent 2a317f41
......@@ -695,7 +695,7 @@ services:
arguments: ['@request_stack', '@config.factory', '@path_processor_manager']
link_generator:
class: Drupal\Core\Utility\LinkGenerator
arguments: ['@url_generator', '@module_handler']
arguments: ['@url_generator', '@module_handler', '@renderer']
router:
class: Drupal\Core\Routing\AccessAwareRouter
arguments: ['@router.no_access_checks', '@access_manager', '@current_user']
......
......@@ -13,6 +13,7 @@
use Drupal\Core\GeneratedLink;
use Drupal\Core\Link;
use Drupal\Core\Path\AliasManagerInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Core\Template\Attribute;
use Drupal\Core\Url;
......@@ -36,6 +37,13 @@ class LinkGenerator implements LinkGeneratorInterface {
*/
protected $moduleHandler;
/**
* The renderer service.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* Constructs a LinkGenerator instance.
*
......@@ -43,10 +51,13 @@ class LinkGenerator implements LinkGeneratorInterface {
* The url generator.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer service.
*/
public function __construct(UrlGeneratorInterface $url_generator, ModuleHandlerInterface $module_handler) {
public function __construct(UrlGeneratorInterface $url_generator, ModuleHandlerInterface $module_handler, RendererInterface $renderer) {
$this->urlGenerator = $url_generator;
$this->moduleHandler = $module_handler;
$this->renderer = $renderer;
}
/**
......@@ -75,8 +86,7 @@ public function generate($text, Url $url, $collect_cacheability_metadata = FALSE
// Start building a structured representation of our link to be altered later.
$variables = array(
// @todo Inject the service when drupal_render() is converted to one.
'text' => is_array($text) ? drupal_render($text) : $text,
'text' => is_array($text) ? $this->renderer->render($text) : $text,
'url' => $url,
'options' => $url->getOptions(),
);
......
......@@ -181,7 +181,7 @@ protected function setUpUrlIntegrationServices() {
\Drupal::getContainer()->set('unrouted_url_assembler', $this->unroutedUrlAssembler);
$this->linkGenerator = new LinkGenerator($this->urlGenerator, $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'));
$this->linkGenerator = new LinkGenerator($this->urlGenerator, $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'), $this->renderer);
}
/**
......
......@@ -43,6 +43,13 @@ class LinkGeneratorTest extends UnitTestCase {
*/
protected $moduleHandler;
/**
* The mocked renderer service.
*
* @var \PHPUnit_Framework_MockObject_MockObject|\Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* The mocked URL Assembler service.
*
......@@ -68,8 +75,8 @@ protected function setUp() {
$this->urlGenerator = $this->getMock('\Drupal\Core\Routing\UrlGenerator', array(), array(), '', FALSE);
$this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface');
$this->linkGenerator = new LinkGenerator($this->urlGenerator, $this->moduleHandler);
$this->renderer = $this->getMock('\Drupal\Core\Render\RendererInterface');
$this->linkGenerator = new LinkGenerator($this->urlGenerator, $this->moduleHandler, $this->renderer);
$this->urlAssembler = $this->getMock('\Drupal\Core\Utility\UnroutedUrlAssemblerInterface');
}
......
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