summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxjm2015-07-04 16:18:11 +0100
committerxjm2015-07-04 16:18:11 +0100
commit0e2ca036540cb18e72cf078e0bf518e82e693dbe (patch)
treea6daf2f324e68d43b283deb677b761ff96b15513
parent0b104695bb2425c62fb442ee3fbd4b21e2983219 (diff)
Issue #2505669 by pwolanin, jcloys, joshi.rohit100, dawehner, Wim Leers, kgoel, larowlan: Inject render service into LinkGenerator instead of calling drupal_render
-rw-r--r--core/core.services.yml2
-rw-r--r--core/lib/Drupal/Core/Utility/LinkGenerator.php16
-rw-r--r--core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php2
-rw-r--r--core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php11
4 files changed, 24 insertions, 7 deletions
diff --git a/core/core.services.yml b/core/core.services.yml
index 0fe0a7f..026f687 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -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']
diff --git a/core/lib/Drupal/Core/Utility/LinkGenerator.php b/core/lib/Drupal/Core/Utility/LinkGenerator.php
index 128dafd..1a9e22f 100644
--- a/core/lib/Drupal/Core/Utility/LinkGenerator.php
+++ b/core/lib/Drupal/Core/Utility/LinkGenerator.php
@@ -13,6 +13,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
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;
@@ -37,16 +38,26 @@ class LinkGenerator implements LinkGeneratorInterface {
protected $moduleHandler;
/**
+ * The renderer service.
+ *
+ * @var \Drupal\Core\Render\RendererInterface
+ */
+ protected $renderer;
+
+ /**
* Constructs a LinkGenerator instance.
*
* @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
* 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 @@ class LinkGenerator implements LinkGeneratorInterface {
// 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(),
);
diff --git a/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php
index 0e45537..11b6eb8 100644
--- a/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php
+++ b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php
@@ -181,7 +181,7 @@ class FieldPluginBaseTest extends UnitTestCase {
\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);
}
/**
diff --git a/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php b/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php
index fde662c..ae8f54e 100644
--- a/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php
+++ b/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php
@@ -44,6 +44,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.
*
* @var \PHPUnit_Framework_MockObject_MockObject|\Drupal\Core\Utility\UnroutedUrlAssemblerInterface
@@ -68,8 +75,8 @@ class LinkGeneratorTest extends UnitTestCase {
$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');
}