Link
class Link implements RenderableInterface (View source)
Defines an object that holds information about a link.
Properties
| protected LinkGeneratorInterface | $linkGenerator | The link generator. |
|
| protected string | $text | The text of the link. |
|
| protected Url | $url | The URL of the link. |
Methods
Creates a Link object from a given route name and parameters.
Creates a Link object from a given Url object.
Returns the text of the link.
Sets the new text of the link.
Generates the HTML for this Link object.
Returns a render array representation of the object.
Returns the link generator.
Details
__construct(string $text, Url $url)
Constructs a new Link object.
static Link
createFromRoute(string $text, string $route_name, array $route_parameters = [], array $options = [])
Creates a Link object from a given route name and parameters.
static Link
fromTextAndUrl(string|array|MarkupInterface $text, Url $url)
Creates a Link object from a given Url object.
string
getText()
Returns the text of the link.
$this
setText(string $text)
Sets the new text of the link.
Url
getUrl()
Returns the URL of the link.
$this
setUrl(Url $url)
Sets the URL of this link.
GeneratedLink
toString()
Generates the HTML for this Link object.
Do not use this method to render a link in an HTML context. In an HTML context, self::toRenderable() should be used so that render cache information is maintained. However, there might be use cases such as tests and non-HTML contexts where calling this method directly makes sense.
array
toRenderable()
Returns a render array representation of the object.
protected LinkGeneratorInterface
getLinkGenerator()
Returns the link generator.
$this
setLinkGenerator(LinkGeneratorInterface $generator)
Sets the link generator service.