public function EntityLinks::resolve in Thunder 6.2.x
Resolve all the links for an entity.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity to act on.
Return value
string[] The entity links.
File
- modules/
thunder_gqls/ src/ Plugin/ GraphQL/ DataProducer/ EntityLinks.php, line 83
Class
- EntityLinks
- Plugin to resolve all the links for an entity.
Namespace
Drupal\thunder_gqls\Plugin\GraphQL\DataProducerCode
public function resolve(EntityInterface $entity) {
$context = new RenderContext();
$result = $this->renderer
->executeInRenderContext($context, function () use ($entity) {
$links = $entity
->getEntityType()
->getLinkTemplates();
array_walk($links, function (&$url, $rel) use ($entity) {
try {
$url = $entity
->toUrl($rel)
->toString();
} catch (\Exception $exception) {
$url = '';
}
});
$transformed_keys = array_map([
$this,
'toCamelCase',
], array_keys($links));
return array_combine($transformed_keys, $links);
});
return $result ?? NULL;
}