public function EntityRendered::resolve in GraphQL 8.4
Resolver.
Parameters
\Drupal\Core\Entity\EntityInterface $entity:
string|null $mode:
\Drupal\Core\Cache\RefinableCacheableDependencyInterface $metadata:
Return value
string
File
- src/
Plugin/ GraphQL/ DataProducer/ Entity/ EntityRendered.php, line 105
Class
- EntityRendered
- Returns the rendered entity in a given view mode.
Namespace
Drupal\graphql\Plugin\GraphQL\DataProducer\EntityCode
public function resolve(EntityInterface $entity, $mode, RefinableCacheableDependencyInterface $metadata) {
$mode = $mode ?? 'full';
$builder = $this->entityTypeManager
->getViewBuilder($entity
->getEntityTypeId());
$view = $builder
->view($entity, $mode, $entity
->language()
->getId());
$context = new RenderContext();
$result = $this->renderer
->executeInRenderContext($context, function () use ($view) {
return $this->renderer
->render($view);
});
if (!$context
->isEmpty()) {
$metadata
->addCacheableDependency($context
->pop());
}
return (string) $result;
}