protected function EntityViewBuilder::alterBuild in Entity API 8.0
Specific per-entity building.
Parameters
array $build: The render array that is being created.
\Drupal\Core\Entity\EntityInterface $entity: The entity to be prepared.
\Drupal\Core\Entity\Display\EntityViewDisplayInterface $display: The entity view display holding the display options configured for the entity components.
string $view_mode: The view mode that should be used to prepare the entity.
Overrides EntityViewBuilder::alterBuild
File
- src/
EntityViewBuilder.php, line 23 - Contains \Drupal\entity\EntityViewBuilder.
Class
- EntityViewBuilder
- Provides a entity view builder with contextual links support
Namespace
Drupal\entityCode
protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
$entity_type_id = $entity
->getEntityTypeId();
if ($entity instanceof ContentEntityInterface && $entity
->isDefaultRevision() || !$entity
->getEntityType()
->isRevisionable()) {
$build['#contextual_links'][$entity_type_id] = [
'route_parameters' => [
$entity_type_id => $entity
->id(),
],
];
}
else {
$build['#contextual_links'][$entity_type_id . '_revision'] = [
'route_parameters' => [
$entity_type_id => $entity
->id(),
$entity_type_id . '_revision' => $entity
->getRevisionId(),
],
];
}
}