trait LinkGeneratorTrait (View source)

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Link instead.

Wrapper methods for the Link Generator.

This utility trait should only be used in application-level code, such as classes that would implement ContainerInjectionInterface. Services registered in the Container should not use this trait but inject the appropriate service directly for easier testing.

Properties

protected LinkGeneratorInterface $linkGenerator

The link generator.

Methods

l($text, Url $url) deprecated

Renders a link to a route given a route name and its parameters.

getLinkGenerator() deprecated

Returns the link generator.

$this
setLinkGenerator(LinkGeneratorInterface $generator) deprecated

Sets the link generator service.

Details

protected GeneratedLink l($text, Url $url) deprecated

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Link::fromTextAndUrl() instead.

Renders a link to a route given a route name and its parameters.

For details on the arguments, usage, and possible exceptions see \Drupal\Core\Utility\LinkGeneratorInterface::generate().

Parameters

$text
Url $url

Return Value

GeneratedLink

A GeneratedLink object containing a link to the given route and parameters and bubbleable metadata.

See also

https://www.drupal.org/node/2614344
LinkGeneratorInterface::generate

protected LinkGeneratorInterface getLinkGenerator() deprecated

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Inject the 'link_generator' service or use \Drupal\Core\Link instead

Returns the link generator.

Return Value

LinkGeneratorInterface

The link generator

See also

https://www.drupal.org/node/2614344

$this setLinkGenerator(LinkGeneratorInterface $generator) deprecated

deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Inject the 'link_generator' service or use \Drupal\Core\Link instead

Sets the link generator service.

Parameters

LinkGeneratorInterface $generator

The link generator service.

Return Value

$this

See also

https://www.drupal.org/node/2614344