public function TwigExtension::drupalLink in Twig Tweak 8.2
Generates a link from an internal path.
Parameters
string $text: The text to be used for the link.
string $user_input: User input for a link or path.
array $options: (optional) An array of options.
bool $check_access: (optional) Indicates that access check is required.
Return value
\Drupal\Core\Link|null A new Link object or null of the URL is not accessible.
See also
\Drupal\Core\Link::fromTextAndUrl()
File
- src/
TwigExtension.php, line 948
Class
- TwigExtension
- Twig extension with some useful functions and filters.
Namespace
Drupal\twig_tweakCode
public function drupalLink($text, $user_input, array $options = [], $check_access = FALSE) {
$url = $this
->drupalUrl($user_input, $options, $check_access);
if ($url) {
// The text has been processed by twig already, convert it to a safe
// object for the render system.
// @see \Drupal\Core\Template\TwigExtension::getLink()
if ($text instanceof \Twig_Markup) {
$text = Markup::create($text);
}
return Link::fromTextAndUrl($text, $url);
}
}