diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 08abcbe..a83624c 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -2615,7 +2615,7 @@ function drupal_common_theme() { 'template' => 'image', ), 'breadcrumb' => array( - 'variables' => array('links' => [], 'breadcrumb' => []), + 'variables' => array('links' => array(), 'breadcrumb' => array()), 'template' => 'breadcrumb', ), 'table' => array( diff --git a/core/lib/Drupal/Core/Link.php b/core/lib/Drupal/Core/Link.php index 90366dd..0ebc72d 100644 --- a/core/lib/Drupal/Core/Link.php +++ b/core/lib/Drupal/Core/Link.php @@ -40,7 +40,7 @@ public function __construct($text, Url $url) { } /** - * Creates a link object from a given route_name/parameters ... + * Creates a link object from a given route name and parameters. * * @param string $text * The text of the link. @@ -99,13 +99,4 @@ public function getUrl() { return $this->url; } - /** - * Generates the HTML representation of the link. - * - * @return string - */ - public function toString() { - return \Drupal::linkGenerator()->generateFromUrl($this->getText(), $this->getUrl()); - } - } diff --git a/core/lib/Drupal/Core/Utility/LinkGenerator.php b/core/lib/Drupal/Core/Utility/LinkGenerator.php index d3093ac..f8660ab 100644 --- a/core/lib/Drupal/Core/Utility/LinkGenerator.php +++ b/core/lib/Drupal/Core/Utility/LinkGenerator.php @@ -11,6 +11,7 @@ use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\String; use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\Link; use Drupal\Core\Path\AliasManagerInterface; use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\Core\Template\Attribute; @@ -50,6 +51,13 @@ public function __construct(UrlGeneratorInterface $url_generator, ModuleHandlerI /** * {@inheritdoc} + */ + public function generateFromLink(Link $link) { + return $this->generateFromUrl($link->getText(), $link->getUrl()); + } + + /** + * {@inheritdoc} * * For anonymous users, the "active" class will be calculated on the server, * because most sites serve each anonymous user the same cached page anyway. diff --git a/core/lib/Drupal/Core/Utility/LinkGeneratorInterface.php b/core/lib/Drupal/Core/Utility/LinkGeneratorInterface.php index e6e74a7..edce761 100644 --- a/core/lib/Drupal/Core/Utility/LinkGeneratorInterface.php +++ b/core/lib/Drupal/Core/Utility/LinkGeneratorInterface.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Utility; +use Drupal\Core\Link; use Drupal\Core\Url; /** @@ -92,4 +93,15 @@ public function generate($text, $route_name, array $parameters = array(), array */ public function generateFromUrl($text, Url $url); + /** + * Renders a link from a link object. + * + * @param \Drupal\Core\Link $link + * A link object to convert to a string. + * + * @return string + * An HTML string containing a link to the given link. + */ + public function generateFromLink(Link $link); + }