Commit 92548664 authored by webchick's avatar webchick

Issue #1154382 by Berdir, barraponto, acouch, swentel, LoMo, chx: Fixed View...

Issue #1154382 by Berdir, barraponto, acouch, swentel, LoMo, chx: Fixed View mode no longer can be changed.
parent e6cfbba9
......@@ -1050,6 +1050,10 @@ function comment_build_content(Comment $comment, Node $node, $view_mode = 'full'
// Remove previously built content, if exists.
$comment->content = array();
// Allow modules to change the view mode.
$context = array('langcode' => $langcode);
drupal_alter('entity_view_mode', $view_mode, $comment, $context);
// Build fields content.
field_attach_prepare_view('comment', array($comment->cid => $comment), $view_mode, $langcode);
entity_prepare_view('comment', array($comment->cid => $comment), $langcode);
......
......@@ -448,3 +448,21 @@ function hook_entity_prepare_view($entities, $entity_type) {
}
}
}
/**
* Change the view mode of an entity that is being displayed.
*
* @param string $view_mode
* The view_mode that is to be used to display the entity.
* @param Drupal\entity\EntityInterface $entity
* The entity that is being viewed.
* @param array $context
* Array with additional context information, currently only contains the
* langcode the entity is viewed in.
*/
function hook_entity_view_mode_alter(&$view_mode, Drupal\entity\EntityInterface $entity, $context) {
// For nodes, change the view mode when it is teaser.
if ($entity->entityType() == 'node' && $view_mode == 'teaser') {
$view_mode = 'my_custom_view_mode';
}
}
......@@ -1202,6 +1202,10 @@ function node_build_content(Node $node, $view_mode = 'full', $langcode = NULL) {
// Remove previously built content, if exists.
$node->content = array();
// Allow modules to change the view mode.
$context = array('langcode' => $langcode);
drupal_alter('entity_view_mode', $view_mode, $node, $context);
// The 'view' hook can be implemented to overwrite the default function
// to display nodes.
if (node_hook($node, 'view')) {
......
......@@ -151,3 +151,13 @@ function node_test_node_update(Node $node) {
}
}
}
/**
* Implements hook_entity_view_mode_alter().
*/
function node_test_entity_view_mode_alter(&$view_mode, Drupal\entity\EntityInterface $entity, $context) {
// Only alter the view mode if we are on the test callback.
if ($change_view_mode = variable_get('node_test_change_view_mode', '')) {
$view_mode = $change_view_mode;
}
}
......@@ -587,6 +587,10 @@ function taxonomy_term_view(Term $term, $view_mode = 'full', $langcode = NULL) {
$langcode = language(LANGUAGE_TYPE_CONTENT)->langcode;
}
// Allow modules to change the view mode.
$context = array('langcode' => $langcode);
drupal_alter('entity_view_mode', $view_mode, $term, $context);
field_attach_prepare_view('taxonomy_term', array($term->tid => $term), $view_mode, $langcode);
entity_prepare_view('taxonomy_term', array($term->tid => $term), $langcode);
......
......@@ -2115,6 +2115,10 @@ function user_build_content($account, $view_mode = 'full', $langcode = NULL) {
// Remove previously built content, if exists.
$account->content = array();
// Allow modules to change the view mode.
$context = array('langcode' => $langcode);
drupal_alter('entity_view_mode', $view_mode, $account, $context);
// Build fields content.
field_attach_prepare_view('user', array($account->uid => $account), $view_mode, $langcode);
entity_prepare_view('user', array($account->uid => $account), $langcode);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment