public function EntityView::processRequest in Services 8.4
Same name and namespace in other branches
- 9.0.x src/Plugin/ServiceDefinition/EntityView.php \Drupal\services\Plugin\ServiceDefinition\EntityView::processRequest()
Processes the request and returns an array of data as appropriate.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The request object.
\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match object.
\Symfony\Component\Serializer\SerializerInterface $serializer: The serializer. Some methods might require the plugin to leverage the serializer after extracting the request contents.
Return value
array The response.
Throws
\Symfony\Component\HttpKernel\Exception\HttpException
Overrides ServiceDefinitionInterface::processRequest
File
- src/
Plugin/ ServiceDefinition/ EntityView.php, line 65
Class
- EntityView
- Plugin annotation @ServiceDefinition( id = "entity_view", methods = { "GET" }, translatable = true, deriver = "\Drupal\services\Plugin\Deriver\EntityView" )
Namespace
Drupal\services\Plugin\ServiceDefinitionCode
public function processRequest(Request $request, RouteMatchInterface $route_match, SerializerInterface $serializer) {
$view_mode = 'full';
if ($request->query
->has('view_mode')) {
$view_mode = $request->query
->get('view_mode');
}
/** @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $this
->getContextValue($this
->getDerivativeId());
$view_builder = \Drupal::entityTypeManager()
->getViewBuilder($entity
->getEntityTypeId());
$render_array = $view_builder
->view($entity, $view_mode);
$result = [];
$result['body'] = $this->renderer
->renderRoot($render_array);
$all_assets = $this
->gatherAssetMarkup($render_array);
$result += $this
->renderAssets($all_assets);
return $result;
}