public function ToUrl::getUrl in Twig Extender 8.2
Same name and namespace in other branches
- 8.4 src/Plugin/TwigPlugin/ToUrl.php \Drupal\twig_extender\Plugin\TwigPlugin\ToUrl::getUrl()
- 8.3 src/Plugin/TwigPlugin/ToUrl.php \Drupal\twig_extender\Plugin\TwigPlugin\ToUrl::getUrl()
- 4.x src/Plugin/TwigPlugin/ToUrl.php \Drupal\twig_extender\Plugin\TwigPlugin\ToUrl::getUrl()
Implementation for render block.
File
- src/
Plugin/ TwigPlugin/ ToUrl.php, line 24
Class
- ToUrl
- The plugin for render a url string of url object or ContentEntityBase object.
Namespace
Drupal\twig_extender\Plugin\TwigPluginCode
public function getUrl($url, $absolute = FALSE) {
if (is_a($url, ContentEntityBase::class)) {
$url = $url
->toUrl();
}
if (is_a($url, 'Drupal\\Core\\Url')) {
$url = $url
->toString();
}
if (gettype($url) !== 'string') {
throw new \Exception('Could not convert object to a path alias');
}
return \Drupal::service('path.alias_manager')
->getAliasByPath($url);
}