protected EntityViewBuilder::getBuildDefaults(EntityInterface $entity, $view_mode)
Provides entity-specific defaults to the build process.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity for which the defaults should be provided.
string $view_mode: The view mode that should be used.
Return value
array
File
- core/lib/Drupal/Core/Entity/EntityViewBuilder.php, line 145
Class
- EntityViewBuilder
- Base class for entity view builders.
Namespace
Drupal\Core\Entity
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | protected function getBuildDefaults(EntityInterface $entity , $view_mode ) { // Allow modules to change the view mode. $context = []; $this ->moduleHandler()->alter( 'entity_view_mode' , $view_mode , $entity , $context ); $build = array ( '#theme' => $this ->entityTypeId, "#{$this->entityTypeId}" => $entity , '#view_mode' => $view_mode , // Collect cache defaults for this entity. '#cache' => array ( 'tags' => Cache::mergeTags( $this ->getCacheTags(), $entity ->getCacheTags()), 'contexts' => $entity ->getCacheContexts(), 'max-age' => $entity ->getCacheMaxAge(), ), ); // Cache the rendered output if permitted by the view mode and global entity // type configuration. if ( $this ->isViewModeCacheable( $view_mode ) && ! $entity ->isNew() && $entity ->isDefaultRevision() && $this ->entityType->isRenderCacheable()) { $build [ '#cache' ] += array ( 'keys' => array ( 'entity_view' , $this ->entityTypeId, $entity ->id(), $view_mode , ), 'bin' => $this ->cacheBin, ); if ( $entity instanceof TranslatableInterface && count ( $entity ->getTranslationLanguages()) > 1) { $build [ '#cache' ][ 'keys' ][] = $entity ->language()->getId(); } } return $build ; } |
Please login to continue.