core/lib/Drupal/Core/Entity/EntityViewBuilder.php | 29 +++++++++++------------ 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php index 2687cd4..df05967 100644 --- a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php @@ -137,6 +137,10 @@ public function buildContent(array &$build, array $entities, array $displays, $v * @return array */ protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langcode) { + // Allow modules to change the view mode. + $context = array('langcode' => $langcode); + $this->moduleHandler()->alter('entity_view_mode', $view_mode, $entity, $context); + $build = array( '#theme' => $this->entityTypeId, "#{$this->entityTypeId}" => $entity, @@ -195,12 +199,12 @@ protected function alterBuild(array &$build, EntityInterface $entity, EntityView public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL) { $build_list = $this->viewMultiple(array($entity), $view_mode, $langcode); - // The default ::buildEntityMultiple() #pre_render callback won't run, - // because we extract a child element of the default renderable array. Thus - // we must assign an alternative #pre_render callback that applies the - // necessary transformations and then still calls ::buildEntityMultiple(). + // The default ::buildMultiple() #pre_render callback won't run, because we + // extract a child element of the default renderable array. Thus we must + // assign an alternative #pre_render callback that applies the necessary + // transformations and then still calls ::buildMultiple(). $build = $build_list[0]; - $build['#pre_render'][] = array($this, 'buildEntity'); + $build['#pre_render'][] = array($this, 'build'); return $build; } @@ -212,12 +216,10 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la if (!isset($langcode)) { $langcode = $this->languageManager->getCurrentLanguage(Language::TYPE_CONTENT)->id; } - // Context is used in the hook_entity_view_mode_alter() invocation below. - $context = array('langcode' => $langcode); $build_list = array( '#sorted' => TRUE, - '#pre_render' => array(array($this, 'buildEntityMultiple')), + '#pre_render' => array(array($this, 'buildMultiple')), '#langcode' => $langcode, ); $weight = 0; @@ -226,9 +228,6 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la // object. $entity = $this->entityManager->getTranslationFromContext($entity, $langcode); - // Allow modules to change the view mode. - $this->moduleHandler()->alter('entity_view_mode', $view_mode, $entity, $context); - // Set build defaults. $build_list[$key] = $this->getBuildDefaults($entity, $view_mode, $langcode); $entityType = $this->entityTypeId; @@ -247,7 +246,7 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la * * It transforms the renderable array for a single entity to the same * structure as if we were rendering multiple entities, and then calls the - * default ::buildEntityMultiple() #pre_render callback. + * default ::buildMultiple() #pre_render callback. * * @param array $build * A renderable array containing build information and context for an entity @@ -258,12 +257,12 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la * * @see drupal_render() */ - public function buildEntity(array $build) { + public function build(array $build) { $build_list = array( '#langcode' => $build['#langcode'], ); $build_list[] = $build; - $build_list = $this->buildEntityMultiple($build_list); + $build_list = $this->buildMultiple($build_list); return $build_list[0]; } @@ -285,7 +284,7 @@ public function buildEntity(array $build) { * * @see drupal_render() */ - public function buildEntityMultiple(array $build_list) { + public function buildMultiple(array $build_list) { // Build the view modes and display objects. $view_modes = array(); $langcode = $build_list['#langcode'];