protected function UrlLinkEnhancer::doUndoTransform in JSON:API Extras 8.3
File
- src/
Plugin/ jsonapi/ FieldEnhancer/ UrlLinkEnhancer.php, line 106
Class
- UrlLinkEnhancer
- Add URL aliases to links.
Namespace
Drupal\jsonapi_extras\Plugin\jsonapi\FieldEnhancerCode
protected function doUndoTransform($data, Context $context) {
if (isset($data['uri'])) {
try {
$url = Url::fromUri($data['uri'], [
'language' => $this->languageManager
->getCurrentLanguage(),
]);
// Use absolute urls if configured.
$configuration = $this
->getConfiguration();
if ($configuration['absolute_url']) {
$url
->setAbsolute(TRUE);
}
$data['url'] = $url
->toString();
} catch (\Exception $e) {
$this->logger
->error('Failed to create a URL from uri @uri. Error: @error', [
'@uri' => $data['uri'],
'@error' => $e
->getMessage(),
]);
}
}
return $data;
}