protected function AliasLinkEnhancer::doUndoTransform in Gatsby Live Preview & Incremental Builds 8
Same name and namespace in other branches
- 2.0.x modules/gatsby_extras/src/Plugin/jsonapi/FieldEnhancer/AliasLinkEnhancer.php \Drupal\gatsby_extras\Plugin\jsonapi\FieldEnhancer\AliasLinkEnhancer::doUndoTransform()
File
- modules/
gatsby_extras/ src/ Plugin/ jsonapi/ FieldEnhancer/ AliasLinkEnhancer.php, line 52
Class
- AliasLinkEnhancer
- Use UUID for internal link field value.
Namespace
Drupal\gatsby_extras\Plugin\jsonapi\FieldEnhancerCode
protected function doUndoTransform($data, Context $context) {
if (isset($data['uri'])) {
// Check if it is a link to an entity.
preg_match("/entity:(.*)\\/(.*)/", $data['uri'], $parsed_uri);
if (!empty($parsed_uri)) {
$entity_type = $parsed_uri[1];
$entity_id = $parsed_uri[2];
$entity = $this->entityTypeManager
->getStorage($entity_type)
->load($entity_id);
if (!is_null($entity)) {
$data['uri_uuid'] = 'entity:' . $entity_type . '/' . $entity
->bundle() . '/' . $entity
->uuid();
$data['uri_alias'] = $entity
->toUrl()
->toString();
}
else {
$data = [
'uri' => '',
'uri_uuid' => '',
'uri_alias' => '',
'title' => '',
'options' => [],
];
}
}
}
return $data;
}