Commit 97c3ee2b authored by webchick's avatar webchick

Issue #1875970 by yched, swentel: Pass EntityDisplay objects to the whole entity_view() callstack.

parent f2e25f60
...@@ -180,8 +180,11 @@ function hook_entity_query_alter(\Drupal\Core\Entity\Query\QueryInterface $query ...@@ -180,8 +180,11 @@ function hook_entity_query_alter(\Drupal\Core\Entity\Query\QueryInterface $query
/** /**
* Act on entities being assembled before rendering. * Act on entities being assembled before rendering.
* *
* @param Drupal\Core\Entity\EntityInterface $entity * @param \Drupal\Core\Entity\EntityInterface $entity
* The entity object. * The entity object.
* @param \Drupal\entity\Plugin\Core\Entity\EntityDisplay $display
* The entity_display object holding the display options configured for the
* entity components.
* @param $view_mode * @param $view_mode
* The view mode the entity is rendered in. * The view mode the entity is rendered in.
* @param $langcode * @param $langcode
...@@ -196,12 +199,16 @@ function hook_entity_query_alter(\Drupal\Core\Entity\Query\QueryInterface $query ...@@ -196,12 +199,16 @@ function hook_entity_query_alter(\Drupal\Core\Entity\Query\QueryInterface $query
* @see hook_node_view() * @see hook_node_view()
* @see hook_user_view() * @see hook_user_view()
*/ */
function hook_entity_view(Drupal\Core\Entity\EntityInterface $entity, $view_mode, $langcode) { function hook_entity_view(\Drupal\Core\Entity\EntityInterface $entity, \Drupal\entity\Plugin\Core\Entity\EntityDisplay $display, $view_mode, $langcode) {
$entity->content['my_additional_field'] = array( // Only do the extra work if the component is configured to be displayed.
'#markup' => $additional_field, // This assumes a 'mymodule_addition' extra field has been defined for the
'#weight' => 10, // entity bundle in hook_field_extra_fields().
'#theme' => 'mymodule_my_additional_field', if ($display->getComponent('mymodule_addition')) {
); $entity->content['mymodule_addition'] = array(
'#markup' => mymodule_addition($entity),
'#theme' => 'mymodule_my_additional_field',
);
}
} }
/** /**
...@@ -221,6 +228,9 @@ function hook_entity_view(Drupal\Core\Entity\EntityInterface $entity, $view_mode ...@@ -221,6 +228,9 @@ function hook_entity_view(Drupal\Core\Entity\EntityInterface $entity, $view_mode
* A renderable array representing the entity content. * A renderable array representing the entity content.
* @param Drupal\Core\Entity\EntityInterface $entity * @param Drupal\Core\Entity\EntityInterface $entity
* The entity object being rendered. * The entity object being rendered.
* @param \Drupal\entity\Plugin\Core\Entity\EntityDisplay $display
* The entity_display object holding the display options configured for the
* entity components.
* *
* @see hook_entity_view() * @see hook_entity_view()
* @see hook_comment_view_alter() * @see hook_comment_view_alter()
...@@ -228,7 +238,7 @@ function hook_entity_view(Drupal\Core\Entity\EntityInterface $entity, $view_mode ...@@ -228,7 +238,7 @@ function hook_entity_view(Drupal\Core\Entity\EntityInterface $entity, $view_mode
* @see hook_taxonomy_term_view_alter() * @see hook_taxonomy_term_view_alter()
* @see hook_user_view_alter() * @see hook_user_view_alter()
*/ */
function hook_entity_view_alter(&$build, Drupal\Core\Entity\EntityInterface $entity) { function hook_entity_view_alter(&$build, Drupal\Core\Entity\EntityInterface $entity, \Drupal\entity\Plugin\Core\Entity\EntityDisplay $display) {
if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) { if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) {
// Change its weight. // Change its weight.
$build['an_additional_field']['#weight'] = -10; $build['an_additional_field']['#weight'] = -10;
...@@ -245,17 +255,33 @@ function hook_entity_view_alter(&$build, Drupal\Core\Entity\EntityInterface $ent ...@@ -245,17 +255,33 @@ function hook_entity_view_alter(&$build, Drupal\Core\Entity\EntityInterface $ent
* view. Only use this if attaching the data during the entity loading phase * view. Only use this if attaching the data during the entity loading phase
* is not appropriate, for example when attaching other 'entity' style objects. * is not appropriate, for example when attaching other 'entity' style objects.
* *
* @param array $entities
* The entities keyed by entity ID.
* @param string $entity_type * @param string $entity_type
* The type of entities being viewed (i.e. node, user, comment). * The type of entities being viewed (i.e. node, user, comment).
* @param array $entities
* The entities keyed by entity ID.
* @param array $display
* The array of entity_display objects holding the display options configured
* for the entity components, keyed by bundle name.
* @param string $view_mode
* The view mode.
*/ */
function hook_entity_prepare_view($entities, $entity_type) { function hook_entity_prepare_view($entity_type, array $entities, array $displays, $view_mode) {
// Load a specific node into the user object for later theming. // Load a specific node into the user object for later theming.
if (!empty($entities) && $entity_type == 'user') { if (!empty($entities) && $entity_type == 'user') {
$nodes = mymodule_get_user_nodes(array_keys($entities)); // Only do the extra work if the component is configured to be
foreach ($entities as $uid => $entity) { // displayed. This assumes a 'mymodule_addition' extra field has been
$entity->user_node = $nodes[$uid]; // defined for the entity bundle in hook_field_extra_fields().
$ids = array();
foreach ($entities as $id => $entity) {
if ($displays[$entity->bundle()]->getComponent('mymodule_addition')) {
$ids[] = $id;
}
}
if ($ids) {
$nodes = mymodule_get_user_nodes($ids);
foreach ($ids as $id) {
$entities[$id]->user_node = $nodes[$id];
}
} }
} }
} }
......
...@@ -662,29 +662,6 @@ function entity_get_render_display(EntityInterface $entity, $view_mode) { ...@@ -662,29 +662,6 @@ function entity_get_render_display(EntityInterface $entity, $view_mode) {
return $display; return $display;
} }
/**
* Adjusts weights and visibility of components in displayed entities.
*
* This is used as a #pre_render callback.
*/
function _entity_view_pre_render($elements) {
$display = $elements['#entity_display'];
$extra_fields = field_info_extra_fields($display->targetEntityType, $display->bundle, 'display');
foreach (array_keys($extra_fields) as $name) {
if (isset($elements[$name]) && (!isset($elements[$name]['#access']) || $elements[$name]['#access'])) {
if ($options = $display->getComponent($name)) {
$elements[$name]['#weight'] = $options['weight'];
}
else {
$elements[$name]['#access'] = FALSE;
}
}
}
return $elements;
}
/** /**
* Returns the entity query object for this entity type. * Returns the entity query object for this entity type.
* *
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
namespace Drupal\Core\Entity; namespace Drupal\Core\Entity;
use Drupal\entity\Plugin\Core\Entity\EntityDisplay;
/** /**
* Base class for entity view controllers. * Base class for entity view controllers.
...@@ -26,54 +27,16 @@ public function __construct($entity_type) { ...@@ -26,54 +27,16 @@ public function __construct($entity_type) {
/** /**
* Implements Drupal\Core\Entity\EntityRenderControllerInterface::buildContent(). * Implements Drupal\Core\Entity\EntityRenderControllerInterface::buildContent().
*/ */
public function buildContent(array $entities = array(), $view_mode = 'full', $langcode = NULL) { public function buildContent(array $entities, array $displays, $view_mode, $langcode = NULL) {
// Allow modules to change the view mode. field_attach_prepare_view($this->entityType, $entities, $displays, $langcode);
$context = array('langcode' => $langcode); module_invoke_all('entity_prepare_view', $this->entityType, $entities, $displays, $view_mode);
$view_modes = array();
$displays = array();
foreach ($entities as $entity) { foreach ($entities as $entity) {
// Remove previously built content, if exists. // Remove previously built content, if exists.
$entity->content = array(); $entity->content = array(
'#view_mode' => $view_mode,
drupal_alter('entity_view_mode', $view_mode, $entity, $context); );
$entity->content['#view_mode'] = $view_mode; $entity->content += field_attach_view($entity, $displays[$entity->bundle()], $langcode);
$view_modes[$view_mode][$entity->id()] = $entity;
$bundle = $entity->bundle();
// Load the corresponding display settings if not stored yet.
if (!isset($displays[$view_mode][$bundle])) {
// Get the display object to use for rendering the entity..
$display = entity_get_render_display($entity, $view_mode);
// Let modules alter the display.
// Note: if config entities get a static cache at some point, the
// objects should be cloned before running drupal_alter().
$display_context = array(
'entity_type' => $this->entityType,
'bundle' => $bundle,
'view_mode' => $view_mode,
);
drupal_alter('entity_display', $display, $display_context);
$displays[$view_mode][$bundle] = $display;
}
// Assigning weights to 'extra fields' is done in a pre_render callback.
$entity->content['#pre_render'] = array('_entity_view_pre_render');
$entity->content['#entity_display'] = $displays[$view_mode][$bundle];
}
// Prepare and build field content, grouped by view mode.
foreach ($view_modes as $view_mode => $view_mode_entities) {
field_attach_prepare_view($this->entityType, $view_mode_entities, $displays[$view_mode], $langcode);
module_invoke_all('entity_prepare_view', $view_mode_entities, $this->entityType);
foreach ($view_mode_entities as $entity) {
$entity->content += field_attach_view($entity, $displays[$view_mode][$entity->bundle()], $langcode);
}
} }
} }
...@@ -105,15 +68,18 @@ protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langco ...@@ -105,15 +68,18 @@ protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langco
* *
* @param array $build * @param array $build
* The render array that is being created. * The render array that is being created.
* @param Drupal\Core\Entity\EntityInterface $entity * @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to be prepared. * The entity to be prepared.
* @param \Drupal\entity\Plugin\Core\Entity\EntityDisplay $display
* The entity_display object holding the display options configured for
* the entity components.
* @param string $view_mode * @param string $view_mode
* The view mode that should be used to prepare the entity. * The view mode that should be used to prepare the entity.
* @param string $langcode * @param string $langcode
* (optional) For which language the entity should be prepared, defaults to * (optional) For which language the entity should be prepared, defaults to
* the current content language. * the current content language.
*/ */
protected function alterBuild(array &$build, EntityInterface $entity, $view_mode, $langcode = NULL) { } protected function alterBuild(array &$build, EntityInterface $entity, EntityDisplay $display, $view_mode, $langcode = NULL) { }
/** /**
* Implements Drupal\Core\Entity\EntityRenderControllerInterface::view(). * Implements Drupal\Core\Entity\EntityRenderControllerInterface::view().
...@@ -130,26 +96,68 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la ...@@ -130,26 +96,68 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la
if (!isset($langcode)) { if (!isset($langcode)) {
$langcode = language(LANGUAGE_TYPE_CONTENT)->langcode; $langcode = language(LANGUAGE_TYPE_CONTENT)->langcode;
} }
$this->buildContent($entities, $view_mode, $langcode);
// Build the view modes and display objects.
$view_modes = array();
$displays = array();
$context = array('langcode' => $langcode);
foreach ($entities as $entity) {
$bundle = $entity->bundle();
// Allow modules to change the view mode.
$entity_view_mode = $view_mode;
drupal_alter('entity_view_mode', $entity_view_mode, $entity, $context);
// Store entities for rendering by view_mode.
$view_modes[$entity_view_mode][$entity->id()] = $entity;
// Load the corresponding display settings if not stored yet.
if (!isset($displays[$entity_view_mode][$bundle])) {
// Get the display object for this bundle and view mode.
$display = entity_get_render_display($entity, $entity_view_mode);
// Let modules alter the display.
$display_context = array(
'entity_type' => $this->entityType,
'bundle' => $bundle,
'view_mode' => $entity_view_mode,
);
drupal_alter('entity_display', $display, $display_context);
$displays[$entity_view_mode][$bundle] = $display;
}
}
foreach ($view_modes as $mode => $view_mode_entities) {
$this->buildContent($view_mode_entities, $displays[$mode], $mode, $langcode);
}
$view_hook = "{$this->entityType}_view"; $view_hook = "{$this->entityType}_view";
$build = array('#sorted' => TRUE); $build = array('#sorted' => TRUE);
$weight = 0; $weight = 0;
foreach ($entities as $key => $entity) { foreach ($entities as $key => $entity) {
$entity_view_mode = isset($entity->content['#view_mode']) ? $entity->content['#view_mode'] : $view_mode; $entity_view_mode = isset($entity->content['#view_mode']) ? $entity->content['#view_mode'] : $view_mode;
module_invoke_all($view_hook, $entity, $entity_view_mode, $langcode); $display = $displays[$entity_view_mode][$entity->bundle()];
module_invoke_all('entity_view', $entity, $entity_view_mode, $langcode); module_invoke_all($view_hook, $entity, $display, $entity_view_mode, $langcode);
module_invoke_all('entity_view', $entity, $display, $entity_view_mode, $langcode);
$build[$key] = $entity->content; $build[$key] = $entity->content;
// We don't need duplicate rendering info in $entity->content. // We don't need duplicate rendering info in $entity->content.
unset($entity->content); unset($entity->content);
$build[$key] += $this->getBuildDefaults($entity, $entity_view_mode, $langcode); $build[$key] += $this->getBuildDefaults($entity, $entity_view_mode, $langcode);
$this->alterBuild($build[$key], $entity, $entity_view_mode, $langcode); $this->alterBuild($build[$key], $entity, $display, $entity_view_mode, $langcode);
// Assign the weights configured in the display.
foreach ($display->getComponents() as $name => $options) {
if (isset($build[$key][$name])) {
$build[$key][$name]['#weight'] = $options['weight'];
}
}
$build[$key]['#weight'] = $weight++; $build[$key]['#weight'] = $weight++;
// Allow modules to modify the structured entity. // Allow modules to modify the render array.
drupal_alter(array($view_hook, 'entity_view'), $build[$key], $entity); drupal_alter(array($view_hook, 'entity_view'), $build[$key], $entity, $display);
} }
return $build; return $build;
......
...@@ -11,13 +11,17 @@ ...@@ -11,13 +11,17 @@
* Defines a common interface for entity view controller classes. * Defines a common interface for entity view controller classes.
*/ */
interface EntityRenderControllerInterface { interface EntityRenderControllerInterface {
/** /**
* Build the structured $content property on the entity. * Build the structured $content property on the entity.
* *
* @param array $entities * @param array $entities
* The entities, implementing EntityInterface, whose content is being built. * The entities, implementing EntityInterface, whose content is being built.
* @param array $displays
* The array of entity_display objects holding the display options
* configured for the entity components, keyed by bundle name.
* @param string $view_mode * @param string $view_mode
* (optional) The view mode that should be used to build the entity. * The view mode in which the entity is being viewed.
* @param string $langcode * @param string $langcode
* (optional) For which language the entity should be build, defaults to * (optional) For which language the entity should be build, defaults to
* the current content language. * the current content language.
...@@ -25,7 +29,7 @@ interface EntityRenderControllerInterface { ...@@ -25,7 +29,7 @@ interface EntityRenderControllerInterface {
* @return array * @return array
* The content array. * The content array.
*/ */
public function buildContent(array $entities = array(), $view_mode = 'full', $langcode = NULL); public function buildContent(array $entities, array $displays, $view_mode, $langcode = NULL);
/** /**
* Returns the render array for the provided entity. * Returns the render array for the provided entity.
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
use Drupal\node\Plugin\Core\Entity\Node; use Drupal\node\Plugin\Core\Entity\Node;
use Drupal\entity\Plugin\Core\Entity\EntityDisplay;
use Drupal\Core\Template\Attribute; use Drupal\Core\Template\Attribute;
/** /**
...@@ -776,7 +777,7 @@ function book_node_load($nodes, $types) { ...@@ -776,7 +777,7 @@ function book_node_load($nodes, $types) {
/** /**
* Implements hook_node_view(). * Implements hook_node_view().
*/ */
function book_node_view(Node $node, $view_mode) { function book_node_view(Node $node, EntityDisplay $display, $view_mode) {
if ($view_mode == 'full') { if ($view_mode == 'full') {
if (!empty($node->book['bid']) && empty($node->in_preview)) { if (!empty($node->book['bid']) && empty($node->in_preview)) {
$node->content['book_navigation'] = array( $node->content['book_navigation'] = array(
......
...@@ -64,8 +64,11 @@ function hook_comment_load(Drupal\comment\Comment $comments) { ...@@ -64,8 +64,11 @@ function hook_comment_load(Drupal\comment\Comment $comments) {
/** /**
* Act on a comment that is being assembled before rendering. * Act on a comment that is being assembled before rendering.
* *
* @param Drupal\comment\Comment $comment * @param \Drupal\comment\Plugin\Core\Entity\Comment $comment $comment
* Passes in the comment the action is being performed on. * Passes in the comment the action is being performed on.
* @param \Drupal\entity\Plugin\Core\Entity\EntityDisplay $display
* The entity_display object holding the display options configured for the
* comment components.
* @param $view_mode * @param $view_mode
* View mode, e.g. 'full', 'teaser'... * View mode, e.g. 'full', 'teaser'...
* @param $langcode * @param $langcode
...@@ -73,9 +76,16 @@ function hook_comment_load(Drupal\comment\Comment $comments) { ...@@ -73,9 +76,16 @@ function hook_comment_load(Drupal\comment\Comment $comments) {
* *
* @see hook_entity_view() * @see hook_entity_view()
*/ */
function hook_comment_view(Drupal\comment\Comment $comment, $view_mode, $langcode) { function hook_comment_view(\Drupal\comment\Plugin\Core\Entity\Comment $comment, \Drupal\entity\Plugin\Core\Entity\EntityDisplay $display, $view_mode, $langcode) {
// how old is the comment // Only do the extra work if the component is configured to be displayed.
$comment->time_ago = time() - $comment->changed; // This assumes a 'mymodule_addition' extra field has been defined for the
// node type in hook_field_extra_fields().
if ($display->getComponent('mymodule_addition')) {
$comment->content['mymodule_addition'] = array(
'#markup' => mymodule_addition($comment),
'#theme' => 'mymodule_my_additional_field',
);
}
} }
/** /**
...@@ -93,13 +103,16 @@ function hook_comment_view(Drupal\comment\Comment $comment, $view_mode, $langcod ...@@ -93,13 +103,16 @@ function hook_comment_view(Drupal\comment\Comment $comment, $view_mode, $langcod
* *
* @param $build * @param $build
* A renderable array representing the comment. * A renderable array representing the comment.
* @param Drupal\comment\Comment $comment * @param \Drupal\comment\Plugin\Core\Entity\Comment $comment
* The comment being rendered. * The comment being rendered.
* @param \Drupal\entity\Plugin\Core\Entity\EntityDisplay $display
* The entity_display object holding the display options configured for the
* comment components.
* *
* @see comment_view() * @see comment_view()
* @see hook_entity_view_alter() * @see hook_entity_view_alter()
*/ */
function hook_comment_view_alter(&$build, Drupal\comment\Comment $comment) { function hook_comment_view_alter(&$build, \Drupal\comment\Plugin\Core\Entity\Comment $comment, \Drupal\entity\Plugin\Core\Entity\EntityDisplay $display) {
// Check for the existence of a field added by another module. // Check for the existence of a field added by another module.
if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) { if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) {
// Change its weight. // Change its weight.
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
*/ */
use Drupal\node\Plugin\Core\Entity\Node; use Drupal\node\Plugin\Core\Entity\Node;
use Drupal\entity\Plugin\Core\Entity\EntityDisplay;
use Drupal\file\Plugin\Core\Entity\File; use Drupal\file\Plugin\Core\Entity\File;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
...@@ -566,7 +567,7 @@ function theme_comment_block($variables) { ...@@ -566,7 +567,7 @@ function theme_comment_block($variables) {
/** /**
* Implements hook_node_view(). * Implements hook_node_view().
*/ */
function comment_node_view(Node $node, $view_mode) { function comment_node_view(Node $node, EntityDisplay $display, $view_mode) {
$links = array(); $links = array();
if ($node->comment != COMMENT_NODE_HIDDEN) { if ($node->comment != COMMENT_NODE_HIDDEN) {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityRenderController; use Drupal\Core\Entity\EntityRenderController;
use Drupal\entity\Plugin\Core\Entity\EntityDisplay;
/** /**
* Render controller for comments. * Render controller for comments.
...@@ -21,7 +22,7 @@ class CommentRenderController extends EntityRenderController { ...@@ -21,7 +22,7 @@ class CommentRenderController extends EntityRenderController {
* In addition to modifying the content key on entities, this implementation * In addition to modifying the content key on entities, this implementation
* will also set the node key which all comments carry. * will also set the node key which all comments carry.
*/ */
public function buildContent(array $entities = array(), $view_mode = 'full', $langcode = NULL) { public function buildContent(array $entities, array $displays, $view_mode, $langcode = NULL) {
$return = array(); $return = array();
if (empty($entities)) { if (empty($entities)) {
return $return; return $return;
...@@ -30,7 +31,7 @@ public function buildContent(array $entities = array(), $view_mode = 'full', $la ...@@ -30,7 +31,7 @@ public function buildContent(array $entities = array(), $view_mode = 'full', $la
// Attach user account. // Attach user account.
user_attach_accounts($entities); user_attach_accounts($entities);
parent::buildContent($entities, $view_mode, $langcode); parent::buildContent($entities, $displays, $view_mode, $langcode);
// Load all nodes of all comments at once. // Load all nodes of all comments at once.
$nids = array(); $nids = array();
...@@ -67,8 +68,8 @@ public function buildContent(array $entities = array(), $view_mode = 'full', $la ...@@ -67,8 +68,8 @@ public function buildContent(array $entities = array(), $view_mode = 'full', $la
/** /**
* Overrides Drupal\Core\Entity\EntityRenderController::alterBuild(). * Overrides Drupal\Core\Entity\EntityRenderController::alterBuild().
*/ */
protected function alterBuild(array &$build, EntityInterface $comment, $view_mode, $langcode = NULL) { protected function alterBuild(array &$build, EntityInterface $comment, EntityDisplay $display, $view_mode, $langcode = NULL) {
parent::alterBuild($build, $comment, $view_mode, $langcode); parent::alterBuild($build, $comment, $display, $view_mode, $langcode);
if (empty($comment->in_preview)) { if (empty($comment->in_preview)) {
$prefix = ''; $prefix = '';
$is_threaded = isset($comment->divs) $is_threaded = isset($comment->divs)
...@@ -95,4 +96,5 @@ protected function alterBuild(array &$build, EntityInterface $comment, $view_mod ...@@ -95,4 +96,5 @@ protected function alterBuild(array &$build, EntityInterface $comment, $view_mod
} }
} }
} }
} }
...@@ -18,19 +18,17 @@ class MessageRenderController extends EntityRenderController { ...@@ -18,19 +18,17 @@ class MessageRenderController extends EntityRenderController {
/** /**
* Overrides Drupal\Core\Entity\EntityRenderController::buildContent(). * Overrides Drupal\Core\Entity\EntityRenderController::buildContent().
*/ */
public function buildContent(array $entities = array(), $view_mode = 'full', $langcode = NULL) { public function buildContent(array $entities, array $displays, $view_mode, $langcode = NULL) {
parent::buildContent($entities, $view_mode, $langcode); parent::buildContent($entities, $displays, $view_mode, $langcode);
foreach ($entities as $entity) { foreach ($entities as $entity) {
// Add the message extra field, if enabled. // Add the message extra field, if enabled.
$entity_view_mode = $entity->content['#view_mode']; $display = $displays[$entity->bundle()];
$fields = field_extra_fields_get_display($entity, $entity_view_mode); if (!empty($entity->message) && $display->getComponent('message')) {
if (!empty($entity->message) && !empty($fields['message']['visible'])) {
$entity->content['message'] = array( $entity->content['message'] = array(
'#type' => 'item', '#type' => 'item',
'#title' => t('Message'), '#title' => t('Message'),
'#markup' => check_plain($entity->message), '#markup' => check_plain($entity->message),
'#weight' => $fields['message']['weight'],
); );
} }
} }
......
...@@ -721,33 +721,6 @@ function field_view_mode_settings($entity_type, $bundle) { ...@@ -721,33 +721,6 @@ function field_view_mode_settings($entity_type, $bundle) {
return $cache[$entity_type][$bundle]; return $cache[$entity_type][$bundle];
} }
/**
* Returns the display options to use for pseudo-fields in a given view mode.
*
* @todo Remove when all steps in the view callstack receive the
* entity_display.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity.
* @param $view_mode
* The view mode.
*
* @return
* The display options to be used when viewing the entity's pseudo-fields in
* the view mode.
*/
function field_extra_fields_get_display(EntityInterface $entity, $view_mode) {
$entity_display = entity_get_render_display($entity, $view_mode);
$extra_fields = field_info_extra_fields($entity->entityType(), $entity->bundle(), 'display');
$options = array();
foreach ($extra_fields as $name => $value) {
$options[$name] = $entity_display->getComponent($name);
}
return $options;
}
/** /**
* Pre-render callback: Adjusts weights and visibility of non-field elements. * Pre-render callback: Adjusts weights and visibility of non-field elements.
*/ */
......
...@@ -38,13 +38,6 @@ abstract class FormatterBase extends PluginSettingsBase implements FormatterInte ...@@ -38,13 +38,6 @@ abstract class FormatterBase extends PluginSettingsBase implements FormatterInte
*/ */
protected $settings; protected $settings;
/**
* The formatter weight.
*
* @var int
*/
protected $weight;
/** /**
* The label display setting. * The label display setting.
* *
...@@ -71,20 +64,17 @@ abstract class FormatterBase extends PluginSettingsBase implements FormatterInte ...@@ -71,20 +64,17 @@ abstract class FormatterBase extends PluginSettingsBase implements FormatterInte
* The field instance to which the formatter is associated. * The field instance to which the formatter is associated.
* @param array $settings * @param array $settings
* The formatter settings. * The formatter settings.
* @param int $weight
* The formatter weight.
* @param string $label * @param string $label
* The formatter label display setting. * The formatter label display setting.
* @param string $view_mode * @param string $view_mode
* The view mode. * The view mode.
*/ */
public function __construct($plugin_id, DiscoveryInterface $discovery, $instance, array $settings, $weight, $label, $view_mode) { public function __construct($plugin_id, DiscoveryInterface $discovery, $instance, array $settings, $label, $view_mode) {
parent::__construct(array(), $plugin_id, $discovery); parent::__construct(array(), $plugin_id, $discovery);
$this->instance = $instance; $this->instance = $instance;
$this->field = field_info_field($instance['field_name']); $this->field = field_info_field($instance['field_name']);
$this->settings = $settings; $this->settings = $settings;
$this->weight = $weight;
$this->label = $label; $this->label = $label;
$this->viewMode = $view_mode; $this->viewMode = $view_mode;
}