summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2014-11-01 17:31:26 -0400
committerDavid Rothstein <drothstein@gmail.com>2014-11-01 17:31:26 -0400
commitc312e5ee5589d060601f633deba3be26df494815 (patch)
tree0db9e745cdbefcec1cb9d6453669139901bf9546 /includes
parent5aede0dadeb785ca30f5e16c6d67281286a047ee (diff)
downloadbrdo-c312e5ee5589d060601f633deba3be26df494815.tar.gz
brdo-c312e5ee5589d060601f633deba3be26df494815.tar.bz2
Issue #1968348 by znerol, David_Rothstein, peximo, DuaelFr: Fixed hook_field_formatter_prepare_view does not make use of hook_entity_view_mode_alter causing major errors.
Diffstat (limited to 'includes')
-rw-r--r--includes/common.inc50
1 files changed, 50 insertions, 0 deletions
diff --git a/includes/common.inc b/includes/common.inc
index 63b691e48..84c5bfa89 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -7899,6 +7899,56 @@ function entity_prepare_view($entity_type, $entities, $langcode = NULL) {
}
/**
+ * Invoke hook_entity_view_mode_alter().
+ *
+ * If adding a new entity similar to nodes, comments or users, you should invoke
+ * this function during the ENTITY_build_content() or ENTITY_view_multiple()
+ * phases of rendering to allow other modules to alter the view mode during this
+ * phase. This function needs to be called before field_attach_prepare_view() to
+ * ensure that the correct content is loaded by field API.
+ *
+ * @param $entity_type
+ * The type of entity, i.e. 'node', 'user'.
+ * @param $entities
+ * The entity objects which are being prepared for view, keyed by object ID.
+ * @param $view_mode
+ * The original view mode e.g. 'full', 'teaser'...
+ * @param $langcode
+ * (optional) A language code to be used for rendering. Defaults to the global
+ * content language of the current request.
+ * @return
+ * An associative array with arrays of entities keyed by view mode.
+ *
+ * @see hook_entity_view_mode_alter()
+ */
+function entity_view_mode_prepare($entity_type, $entities, $view_mode, $langcode = NULL) {
+ if (!isset($langcode)) {
+ $langcode = $GLOBALS['language_content']->language;
+ }
+
+ // To ensure hooks are never run after field_attach_prepare_view() only
+ // process items without the entity_view_prepared flag.
+ $entities_by_view_mode = array();
+ foreach ($entities as $id => $entity) {
+ $entity_view_mode = $view_mode;
+ if (empty($entity->entity_view_prepared)) {
+
+ // Allow modules to change the view mode.
+ $context = array(
+ 'entity_type' => $entity_type,
+ 'entity' => $entity,
+ 'langcode' => $langcode,
+ );
+ drupal_alter('entity_view_mode', $entity_view_mode, $context);
+ }
+
+ $entities_by_view_mode[$entity_view_mode][$id] = $entity;
+ }
+
+ return $entities_by_view_mode;
+}
+
+/**
* Returns the URI elements of an entity.
*
* @param $entity_type