public function UrlValue::getUrlValue in Twig Extender 4.x
Same name and namespace in other branches
- 8.4 modules/twig_extender_extras/src/Plugin/TwigPlugin/UrlValue.php \Drupal\twig_extender_extras\Plugin\TwigPlugin\UrlValue::getUrlValue()
- 8.2 modules/twig_extender_extras/src/Plugin/TwigPlugin/UrlValue.php \Drupal\twig_extender_extras\Plugin\TwigPlugin\UrlValue::getUrlValue()
- 8.3 modules/twig_extender_extras/src/Plugin/TwigPlugin/UrlValue.php \Drupal\twig_extender_extras\Plugin\TwigPlugin\UrlValue::getUrlValue()
Get a url value from a link field.
Parameters
\Drupal\Core\Field\Plugin\DataType\FieldItem $field: Field item from type link.
Return value
\Drupal\Core\Url Url object.
Throws
\Exception
File
- modules/
twig_extender_extras/ src/ Plugin/ TwigPlugin/ UrlValue.php, line 32
Class
- UrlValue
- The plugin for render a url string of a link field object.
Namespace
Drupal\twig_extender_extras\Plugin\TwigPluginCode
public function getUrlValue(FieldItem $field) {
try {
$field_type = $field
->getFieldDefinition()
->getType();
if ($field_type == 'link') {
$uri = $field
->first()
->getUrl();
return $uri;
}
} catch (\Exception $e) {
\Drupal::logger('twig_extender_extras')
->error($e
->getMessage());
throw $e;
}
}