core/includes/common.inc | 4 +-- core/lib/Drupal/Core/Entity/EntityViewBuilder.php | 36 +++++++++++++--------- .../Core/Entity/EntityViewBuilderInterface.php | 5 +-- core/modules/block/block.api.php | 2 +- .../custom_block_test/custom_block_test.module | 4 +-- .../block/lib/Drupal/block/BlockViewBuilder.php | 1 - core/modules/book/book.module | 4 +-- core/modules/comment/comment.api.php | 10 +++--- core/modules/comment/comment.module | 2 +- .../lib/Drupal/contact/MessageViewBuilder.php | 2 +- core/modules/edit/edit.module | 2 +- core/modules/edit/tests/modules/edit_test.module | 2 +- .../lib/Drupal/entity/Entity/EntityViewDisplay.php | 2 +- core/modules/history/history.module | 2 +- core/modules/node/node.api.php | 15 ++++----- .../node/tests/modules/node_test/node_test.module | 6 ++-- core/modules/statistics/statistics.module | 6 ++-- core/modules/system/entity.api.php | 10 +++--- core/modules/taxonomy/taxonomy.api.php | 17 +++++----- core/modules/user/user.api.php | 12 +++++--- core/modules/user/user.module | 6 ++-- 21 files changed, 80 insertions(+), 70 deletions(-) diff --git a/core/includes/common.inc b/core/includes/common.inc index a780525..d10b9ca 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -3269,7 +3269,7 @@ function drupal_pre_render_link($element) { * A typical example comes from node links, which are stored in a renderable * array similar to this: * @code - * $node->content['links'] = array( + * $build['links'] = array( * '#theme' => 'links__node', * '#pre_render' => array('drupal_pre_render_links'), * 'comment' => array( @@ -3304,7 +3304,7 @@ function drupal_pre_render_link($element) { * {{ content.links.comment }} * @endcode * - * (where $node->content has been transformed into $content before handing + * (where a node's content has been transformed into $content before handing * control to the node.html.twig template). * * The pre_render function defined here allows the above flexibility, but also diff --git a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php index d46bdfc..e18c9a6 100644 --- a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php @@ -120,7 +120,7 @@ public function buildContent(array &$build, array $entities, array $displays, $v foreach ($entities_by_bundle as $bundle => $bundle_entities) { $display_build = $displays[$bundle]->buildMultiple($bundle_entities); foreach ($bundle_entities as $id => $entity) { - $build = NestedArray::mergeDeepArray(array($build, array('#view_mode' => $view_mode), $display_build[$id]), TRUE); + $build[$id] = NestedArray::mergeDeepArray(array($build[$id], array('#view_mode' => $view_mode), $display_build[$id]), TRUE); } } } @@ -183,30 +183,36 @@ protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langco /** * Builds an entity's view on an entity view; augments entity defaults. * - * This function is assigned as a #build callback in + * This function is assigned as a #pre_render callback in * \Drupal\Core\Entity\EntityViewBuilder::getBuildDefaults(). * - * @param array $elements - * A structured array containing build information and context for an + * @param array $build + * A renderable array containing build information and context for an * entity view. * + * @return array + * The updated renderable array. + * * @see drupal_render() */ - public function entityViewBuilderBuildView(array $elements) { - $entity = $elements['#entity']; + public function entityViewBuilderBuildView(array $build) { + $entity = $build['#entity']; $bundle = $entity->bundle(); + $id = $entity->id(); $view_hook = "{$this->entityTypeId}_view"; - $view_mode = $elements['#view_mode']; - $langcode = $elements['#langcode']; + $view_mode = $build['#view_mode']; + $langcode = $build['#langcode']; - // Get the corresponding display settings. + // Build all visible components. $display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode); - - // Build field renderables. - $build = $elements; - $this->buildContent($build, array($entity->id() => $entity), array($bundle => $display), $view_mode, $langcode); - $view_mode = isset($build['#view_mode']) ? $build['#view_mode'] : $view_mode; - + // EntityViewBuilderInterface::buildContent() works on multiple entities + // simultaneously, yet $build is only for a single entity. Therefore, + // perform the necessary transformations before and after calling it. + $build_per_entity = array($id => $build); + $this->buildContent($build_per_entity, array($id => $entity), array($bundle => $display), $view_mode, $langcode); + $build = $build_per_entity[$id]; + + // Allow for alterations while building, before rendering. $this->moduleHandler()->invokeAll($view_hook, array(&$build, $entity, $display, $view_mode, $langcode)); $this->moduleHandler()->invokeAll('entity_view', array(&$build, $entity, $display, $view_mode, $langcode)); $this->alterBuild($build, $entity, $display, $view_mode, $langcode); diff --git a/core/lib/Drupal/Core/Entity/EntityViewBuilderInterface.php b/core/lib/Drupal/Core/Entity/EntityViewBuilderInterface.php index c9e736e..dd658b0 100644 --- a/core/lib/Drupal/Core/Entity/EntityViewBuilderInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilderInterface.php @@ -18,7 +18,7 @@ /** * Build the structured $content property on the entity. * - * @param $build + * @param &$build * The elements being built. * @param \Drupal\Core\Entity\EntityInterface[] $entities * The entities whose content is being built. @@ -30,9 +30,6 @@ * @param string $langcode * (optional) For which language the entity should be build, defaults to * the current content language. - * - * @return array - * The content array. */ public function buildContent(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL); diff --git a/core/modules/block/block.api.php b/core/modules/block/block.api.php index 065a1cd..9210f82 100644 --- a/core/modules/block/block.api.php +++ b/core/modules/block/block.api.php @@ -27,7 +27,7 @@ * is hook_block_view_BASE_BLOCK_ID_alter(), which can be used to target a * specific block or set of similar blocks. * - * @param array $build + * @param array &$build * A renderable array of data, as returned from the build() implementation of * the plugin that defined the block: * - #title: The default localized title of the block. diff --git a/core/modules/block/custom_block/tests/modules/custom_block_test/custom_block_test.module b/core/modules/block/custom_block/tests/modules/custom_block_test/custom_block_test.module index 8c53053..65e9c56 100644 --- a/core/modules/block/custom_block/tests/modules/custom_block_test/custom_block_test.module +++ b/core/modules/block/custom_block/tests/modules/custom_block_test/custom_block_test.module @@ -13,9 +13,9 @@ /** * Implements hook_custom_block_view(). */ -function custom_block_test_custom_block_view(CustomBlock $custom_block, $view_mode) { +function custom_block_test_custom_block_view(array &$build, CustomBlock $custom_block, $view_mode) { // Add extra content. - $custom_block->content['extra_content'] = array( + $build['extra_content'] = array( '#markup' => 'Yowser', ); } diff --git a/core/modules/block/lib/Drupal/block/BlockViewBuilder.php b/core/modules/block/lib/Drupal/block/BlockViewBuilder.php index f990086..1f852be 100644 --- a/core/modules/block/lib/Drupal/block/BlockViewBuilder.php +++ b/core/modules/block/lib/Drupal/block/BlockViewBuilder.php @@ -23,7 +23,6 @@ class BlockViewBuilder extends EntityViewBuilder { * {@inheritdoc} */ public function buildContent(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL) { - return array(); } /** diff --git a/core/modules/book/book.module b/core/modules/book/book.module index 8c52221..e5bb818 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -247,11 +247,11 @@ function book_node_load($nodes) { /** * Implements hook_node_view(). */ -function book_node_view(EntityInterface $node, EntityViewDisplayInterface $display, $view_mode) { +function book_node_view(array &$build, EntityInterface $node, EntityViewDisplayInterface $display, $view_mode) { if ($view_mode == 'full') { if (!empty($node->book['bid']) && empty($node->in_preview)) { $book_navigation = array( '#theme' => 'book_navigation', '#book_link' => $node->book); - $node->content['book_navigation'] = array( + $build['book_navigation'] = array( '#markup' => drupal_render($book_navigation), '#weight' => 100, '#attached' => array( diff --git a/core/modules/comment/comment.api.php b/core/modules/comment/comment.api.php index 8507f13..9d77557 100644 --- a/core/modules/comment/comment.api.php +++ b/core/modules/comment/comment.api.php @@ -84,6 +84,8 @@ function hook_comment_load(Drupal\comment\Comment $comments) { /** * Act on a comment that is being assembled before rendering. * + * @param array &$build + * A renderable array representing the comment content. * @param \Drupal\comment\Entity\Comment $comment $comment * Passes in the comment the action is being performed on. * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display @@ -96,12 +98,12 @@ function hook_comment_load(Drupal\comment\Comment $comments) { * * @see hook_entity_view() */ -function hook_comment_view(\Drupal\comment\Entity\Comment $comment, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode, $langcode) { +function hook_comment_view(array &$build, \Drupal\comment\Entity\Comment $comment, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode, $langcode) { // Only do the extra work if the component is configured to be displayed. // This assumes a 'mymodule_addition' extra field has been defined for the // node type in hook_entity_extra_field_info(). if ($display->getComponent('mymodule_addition')) { - $comment->content['mymodule_addition'] = array( + $build['mymodule_addition'] = array( '#markup' => mymodule_addition($comment), '#theme' => 'mymodule_my_additional_field', ); @@ -120,7 +122,7 @@ function hook_comment_view(\Drupal\comment\Entity\Comment $comment, \Drupal\Core * callback. Alternatively, it could also implement hook_preprocess_HOOK() for * comment.html.twig. See drupal_render() documentation for details. * - * @param $build + * @param array &$build * A renderable array representing the comment. * @param \Drupal\comment\Entity\Comment $comment * The comment being rendered. @@ -131,7 +133,7 @@ function hook_comment_view(\Drupal\comment\Entity\Comment $comment, \Drupal\Core * @see comment_view() * @see hook_entity_view_alter() */ -function hook_comment_view_alter(&$build, \Drupal\comment\Entity\Comment $comment, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display) { +function hook_comment_view_alter(array &$build, \Drupal\comment\Entity\Comment $comment, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display) { // Check for the existence of a field added by another module. if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) { // Change its weight. diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 8025334..3a197e5 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -537,7 +537,7 @@ function comment_node_links_alter(array &$node_links, NodeInterface $node, array /** * Implements hook_node_view_alter(). */ -function comment_node_view_alter(&$build, EntityInterface $node, EntityViewDisplayInterface $display) { +function comment_node_view_alter(array &$build, EntityInterface $node, EntityViewDisplayInterface $display) { if (\Drupal::moduleHandler()->moduleExists('history')) { $build['#attributes']['data-history-node-id'] = $node->id(); } diff --git a/core/modules/contact/lib/Drupal/contact/MessageViewBuilder.php b/core/modules/contact/lib/Drupal/contact/MessageViewBuilder.php index 5775129..701336c 100644 --- a/core/modules/contact/lib/Drupal/contact/MessageViewBuilder.php +++ b/core/modules/contact/lib/Drupal/contact/MessageViewBuilder.php @@ -21,7 +21,7 @@ class MessageViewBuilder extends EntityViewBuilder { * {@inheritdoc} */ public function buildContent(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL) { - parent::buildContent($entities, $displays, $view_mode, $langcode); + parent::buildContent($build, $entities, $displays, $view_mode, $langcode); foreach ($entities as $id => $entity) { // Add the message extra field, if enabled. diff --git a/core/modules/edit/edit.module b/core/modules/edit/edit.module index 6c8e90f..a937b3b 100644 --- a/core/modules/edit/edit.module +++ b/core/modules/edit/edit.module @@ -141,7 +141,7 @@ function edit_preprocess_field(&$variables) { /** * Implements hook_entity_view_alter(). */ -function edit_entity_view_alter(&$build, EntityInterface $entity, EntityViewDisplayInterface $display) { +function edit_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) { $build['#attributes']['data-edit-entity-id'] = $entity->getEntityTypeId() . '/' . $entity->id(); } diff --git a/core/modules/edit/tests/modules/edit_test.module b/core/modules/edit/tests/modules/edit_test.module index 624c71b..3124e2f 100644 --- a/core/modules/edit/tests/modules/edit_test.module +++ b/core/modules/edit/tests/modules/edit_test.module @@ -12,7 +12,7 @@ /** * Implements hook_entity_view_alter(). */ -function edit_test_entity_view_alter(&$build, EntityInterface $entity, EntityViewDisplayInterface $display) { +function edit_test_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) { if ($entity->getEntityTypeId() == 'node' && $entity->bundle() == 'article') { $build['pseudo'] = array( '#theme' => 'field', diff --git a/core/modules/entity/lib/Drupal/entity/Entity/EntityViewDisplay.php b/core/modules/entity/lib/Drupal/entity/Entity/EntityViewDisplay.php index bf7cf67..cfd9476 100644 --- a/core/modules/entity/lib/Drupal/entity/Entity/EntityViewDisplay.php +++ b/core/modules/entity/lib/Drupal/entity/Entity/EntityViewDisplay.php @@ -211,7 +211,7 @@ public function build(ContentEntityInterface $entity) { public function buildMultiple(array $entities) { $build = array(); foreach ($entities as $key => $entity) { - $build[$key] = $entity->content; + $build[$key] = array(); } // Run field formatters. diff --git a/core/modules/history/history.module b/core/modules/history/history.module index 35e3aa1..e7ab073 100644 --- a/core/modules/history/history.module +++ b/core/modules/history/history.module @@ -131,7 +131,7 @@ function history_cron() { /** * Implements hook_node_view_alter(). */ -function history_node_view_alter(&$build, EntityInterface $node, EntityViewDisplayInterface $display) { +function history_node_view_alter(array &$build, EntityInterface $node, EntityViewDisplayInterface $display) { // Update the history table, stating that this user viewed this node. if (($display->originalMode === 'full') && \Drupal::currentUser()->isAuthenticated()) { $build['#attached'] = array( diff --git a/core/modules/node/node.api.php b/core/modules/node/node.api.php index 4ea7212..30662b5 100644 --- a/core/modules/node/node.api.php +++ b/core/modules/node/node.api.php @@ -770,15 +770,16 @@ function hook_node_submit(\Drupal\node\NodeInterface $node, $form, &$form_state) /** * Act on a node that is being assembled before rendering. * - * The module may add elements to $node->content prior to rendering. - * The structure of $node->content is a renderable array as expected by - * drupal_render(). + * The module may add elements to a node's renderable array array prior to + * rendering. * * When $view_mode is 'rss', modules can also add extra RSS elements and * namespaces to $node->rss_elements and $node->rss_namespaces respectively for * the RSS item generated for this node. * For details on how this is used, see node_feed(). * + * @param array &$build + * A renderable array representing the node content. * @param \Drupal\node\NodeInterface $node * The node that is being assembled for rendering. * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display @@ -794,12 +795,12 @@ function hook_node_submit(\Drupal\node\NodeInterface $node, $form, &$form_state) * * @ingroup node_api_hooks */ -function hook_node_view(\Drupal\node\NodeInterface $node, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode, $langcode) { +function hook_node_view(array &$build, \Drupal\node\NodeInterface $node, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode, $langcode) { // Only do the extra work if the component is configured to be displayed. // This assumes a 'mymodule_addition' extra field has been defined for the // node type in hook_entity_extra_field_info(). if ($display->getComponent('mymodule_addition')) { - $node->content['mymodule_addition'] = array( + $build['mymodule_addition'] = array( '#markup' => mymodule_addition($node), '#theme' => 'mymodule_my_additional_field', ); @@ -819,7 +820,7 @@ function hook_node_view(\Drupal\node\NodeInterface $node, \Drupal\Core\Entity\Di * node.html.twig. See drupal_render() and _theme() documentation respectively * for details. * - * @param $build + * @param &$build * A renderable array representing the node content. * @param \Drupal\node\NodeInterface $node * The node being rendered. @@ -832,7 +833,7 @@ function hook_node_view(\Drupal\node\NodeInterface $node, \Drupal\Core\Entity\Di * * @ingroup node_api_hooks */ -function hook_node_view_alter(&$build, \Drupal\node\NodeInterface $node, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display) { +function hook_node_view_alter(array &$build, \Drupal\node\NodeInterface $node, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display) { if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) { // Change its weight. $build['an_additional_field']['#weight'] = -10; diff --git a/core/modules/node/tests/modules/node_test/node_test.module b/core/modules/node/tests/modules/node_test/node_test.module index 398f132..f9294c8 100644 --- a/core/modules/node/tests/modules/node_test/node_test.module +++ b/core/modules/node/tests/modules/node_test/node_test.module @@ -14,7 +14,7 @@ /** * Implements hook_node_view(). */ -function node_test_node_view(NodeInterface $node, EntityViewDisplayInterface $display, $view_mode) { +function node_test_node_view(array &$build, NodeInterface $node, EntityViewDisplayInterface $display, $view_mode) { if ($view_mode == 'rss') { // Add RSS elements and namespaces when building the RSS feed. $node->rss_elements[] = array( @@ -23,7 +23,7 @@ function node_test_node_view(NodeInterface $node, EntityViewDisplayInterface $di ); // Add content that should be displayed only in the RSS feed. - $node->content['extra_feed_content'] = array( + $build['extra_feed_content'] = array( '#markup' => '

' . t('Extra data that should appear only in the RSS feed for node !nid.', array('!nid' => $node->id())) . '

', '#weight' => 10, ); @@ -31,7 +31,7 @@ function node_test_node_view(NodeInterface $node, EntityViewDisplayInterface $di if ($view_mode != 'rss') { // Add content that should NOT be displayed in the RSS feed. - $node->content['extra_non_feed_content'] = array( + $build['extra_non_feed_content'] = array( '#markup' => '

' . t('Extra data that should appear everywhere except the RSS feed for node !nid.', array('!nid' => $node->id())) . '

', ); } diff --git a/core/modules/statistics/statistics.module b/core/modules/statistics/statistics.module index 8877181..4b2110c 100644 --- a/core/modules/statistics/statistics.module +++ b/core/modules/statistics/statistics.module @@ -48,11 +48,11 @@ function statistics_permission() { /** * Implements hook_node_view(). */ -function statistics_node_view(EntityInterface $node, EntityViewDisplayInterface $display, $view_mode) { +function statistics_node_view(array &$build, EntityInterface $node, EntityViewDisplayInterface $display, $view_mode) { if (!$node->isNew() && $view_mode == 'full' && node_is_page($node) && empty($node->in_preview)) { - $node->content['statistics_content_counter']['#attached']['library'][] = 'statistics/drupal.statistics'; + $build['statistics_content_counter']['#attached']['library'][] = 'statistics/drupal.statistics'; $settings = array('data' => array('nid' => $node->id()), 'url' => url(drupal_get_path('module', 'statistics') . '/statistics.php')); - $node->content['statistics_content_counter']['#attached']['js'][] = array( + $build['statistics_content_counter']['#attached']['js'][] = array( 'data' => array('statistics' => $settings), 'type' => 'setting', ); diff --git a/core/modules/system/entity.api.php b/core/modules/system/entity.api.php index de56753..d1465e2 100644 --- a/core/modules/system/entity.api.php +++ b/core/modules/system/entity.api.php @@ -436,7 +436,7 @@ function hook_entity_query_alter(\Drupal\Core\Entity\Query\QueryInterface $query /** * Act on entities being assembled before rendering. * - * @param $build + * @param &$build * A renderable array representing the entity content. * @param \Drupal\Core\Entity\EntityInterface $entity * The entity object. @@ -457,12 +457,12 @@ function hook_entity_query_alter(\Drupal\Core\Entity\Query\QueryInterface $query * @see hook_node_view() * @see hook_user_view() */ -function hook_entity_view(&$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode, $langcode) { +function hook_entity_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode, $langcode) { // Only do the extra work if the component is configured to be displayed. // This assumes a 'mymodule_addition' extra field has been defined for the // entity bundle in hook_entity_extra_field_info(). if ($display->getComponent('mymodule_addition')) { - $entity->content['mymodule_addition'] = array( + $build['mymodule_addition'] = array( '#markup' => mymodule_addition($entity), '#theme' => 'mymodule_my_additional_field', ); @@ -482,7 +482,7 @@ function hook_entity_view(&$build, \Drupal\Core\Entity\EntityInterface $entity, * the particular entity type template, if there is one (e.g., node.html.twig). * See drupal_render() and _theme() for details. * - * @param $build + * @param array &$build * A renderable array representing the entity content. * @param \Drupal\Core\Entity\EntityInterface $entity * The entity object being rendered. @@ -496,7 +496,7 @@ function hook_entity_view(&$build, \Drupal\Core\Entity\EntityInterface $entity, * @see hook_taxonomy_term_view_alter() * @see hook_user_view_alter() */ -function hook_entity_view_alter(&$build, Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display) { +function hook_entity_view_alter(array &$build, Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display) { if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) { // Change its weight. $build['an_additional_field']['#weight'] = -10; diff --git a/core/modules/taxonomy/taxonomy.api.php b/core/modules/taxonomy/taxonomy.api.php index 960cff2..9fa84c1 100644 --- a/core/modules/taxonomy/taxonomy.api.php +++ b/core/modules/taxonomy/taxonomy.api.php @@ -243,10 +243,11 @@ function hook_taxonomy_term_delete(Drupal\taxonomy\Term $term) { /** * Act on a taxonomy term that is being assembled before rendering. * - * The module may add elements to $term->content prior to rendering. The - * structure of $term->content is a renderable array as expected by - * drupal_render(). - * + * The module may add elements to a taxonomy term's renderable array array prior + * to rendering. + + * @param array &$build + * A renderable array representing the taxonomy term content. * @param \Drupal\taxonomy\Entity\Term $term * The term that is being assembled for rendering. * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display @@ -259,12 +260,12 @@ function hook_taxonomy_term_delete(Drupal\taxonomy\Term $term) { * * @see hook_entity_view() */ -function hook_taxonomy_term_view(\Drupal\taxonomy\Entity\Term $term, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode, $langcode) { +function hook_taxonomy_term_view(array &$build, \Drupal\taxonomy\Entity\Term $term, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode, $langcode) { // Only do the extra work if the component is configured to be displayed. // This assumes a 'mymodule_addition' extra field has been defined for the // vocabulary in hook_entity_extra_field_info(). if ($display->getComponent('mymodule_addition')) { - $term->content['mymodule_addition'] = array( + $build['mymodule_addition'] = array( '#markup' => mymodule_addition($term), '#theme' => 'mymodule_my_additional_field', ); @@ -284,7 +285,7 @@ function hook_taxonomy_term_view(\Drupal\taxonomy\Entity\Term $term, \Drupal\Cor * hook_preprocess_HOOK() for taxonomy-term.html.twig. See drupal_render() and * _theme() documentation respectively for details. * - * @param $build + * @param array &$build * A renderable array representing the taxonomy term content. * @param \Drupal\taxonomy\Entity\Term $term * The taxonomy term being rendered. @@ -294,7 +295,7 @@ function hook_taxonomy_term_view(\Drupal\taxonomy\Entity\Term $term, \Drupal\Cor * * @see hook_entity_view_alter() */ -function hook_taxonomy_term_view_alter(&$build, \Drupal\taxonomy\Entity\Term $term, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display) { +function hook_taxonomy_term_view_alter(array &$build, \Drupal\taxonomy\Entity\Term $term, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display) { if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) { // Change its weight. $build['an_additional_field']['#weight'] = -10; diff --git a/core/modules/user/user.api.php b/core/modules/user/user.api.php index b71a65f..ab6e2b6 100644 --- a/core/modules/user/user.api.php +++ b/core/modules/user/user.api.php @@ -306,8 +306,10 @@ function hook_user_logout($account) { * The user's account information is being displayed. * * The module should format its custom additions for display and add them to the - * $account->content array. + * $build array. * + * @param array &$build + * A renderable array representing the user content. * @param \Drupal\user\UserInterface $account * The user object on which the operation is being performed. * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display @@ -321,12 +323,12 @@ function hook_user_logout($account) { * @see hook_user_view_alter() * @see hook_entity_view() */ -function hook_user_view(\Drupal\user\UserInterface $account, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode, $langcode) { +function hook_user_view(array &$build, \Drupal\user\UserInterface $account, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode, $langcode) { // Only do the extra work if the component is configured to be displayed. // This assumes a 'mymodule_addition' extra field has been defined for the // user entity type in hook_entity_extra_field_info(). if ($display->getComponent('mymodule_addition')) { - $account->content['mymodule_addition'] = array( + $build['mymodule_addition'] = array( '#markup' => mymodule_addition($account), '#theme' => 'mymodule_my_additional_field', ); @@ -346,7 +348,7 @@ function hook_user_view(\Drupal\user\UserInterface $account, \Drupal\Core\Entity * user.html.twig. See drupal_render() and _theme() documentation * respectively for details. * - * @param $build + * @param array &$build * A renderable array representing the user. * @param \Drupal\user\UserInterface $account * The user account being rendered. @@ -357,7 +359,7 @@ function hook_user_view(\Drupal\user\UserInterface $account, \Drupal\Core\Entity * @see user_view() * @see hook_entity_view_alter() */ -function hook_user_view_alter(&$build, \Drupal\user\UserInterface $account, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display) { +function hook_user_view_alter(array &$build, \Drupal\user\UserInterface $account, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display) { // Check for the existence of a field added by another module. if (isset($build['an_additional_field'])) { // Change its weight. diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 38983df..4304b2a 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -168,10 +168,12 @@ function user_uri($user) { * Called by Drupal\Core\Entity\EntityViewBuilderInterface::buildContent() * implementations. * + * @param array &$build + * A renderable array representing the entity content. * @param \Drupal\user\EntityOwnerInterface[] $entities * The entities keyed by entity ID. */ -function user_attach_accounts(&$build, array $entities) { +function user_attach_accounts(array &$build, array $entities) { $uids = array(); foreach ($entities as $entity) { $uids[] = $entity->getOwnerId(); @@ -503,7 +505,7 @@ function user_permission() { /** * Implements hook_user_view(). */ -function user_user_view(&$build, UserInterface $account, EntityViewDisplayInterface $display) { +function user_user_view(array &$build, UserInterface $account, EntityViewDisplayInterface $display) { if ($display->getComponent('member_for')) { $build['member_for'] = array( '#type' => 'item',