function panelizer_entity_view_alter in Panelizer 7.3
Implements hook_entity_view_alter().
File
- ./
panelizer.module, line 353 - The Panelizer module attaches panels to entities, providing default panels and allowing each panel to be configured independently by privileged users.
Code
function panelizer_entity_view_alter(&$build, $entity_type) {
static $recursion_prevention = array();
// Prepare variables.
$handler = panelizer_entity_plugin_get_handler($entity_type);
if (!$handler) {
return;
}
$entity = $handler
->get_entity_view_entity($build);
// Safety check in case the entity can't be loaded.
if (!$entity) {
return;
}
list($entity_id, $revision_id, $bundle) = entity_extract_ids($entity_type, $entity);
// If the requested view mode does not exist, check if a substitute is
// assigned, otherwise rendering will fall back to 'default' and we should
// check that one instead.
$view_mode = $handler
->get_view_mode($build['#view_mode'], $bundle);
// Make sure the bundle + view mode is actually panelized!
if (!$handler
->is_panelized($bundle . '.' . $view_mode)) {
return;
}
// Also verify that the configuration exists. This may happen if a display is
// improperly configured.
if (empty($entity->panelizer[$view_mode])) {
return;
}
if (!empty($recursion_prevention[$entity_type][$entity_id][$view_mode])) {
return;
}
$recursion_prevention[$entity_type][$entity_id][$view_mode] = TRUE;
if ($info = $handler
->render_entity($entity, $view_mode)) {
// Change theming function and add the content on the $build array.
$build['#theme'] = 'panelizer_view_mode';
$build['#panelizer'] = $entity->panelizer[$view_mode];
$build['#panelizer_content'] = $info;
$build['#panelizer_handler'] = $handler;
$build['#panelizer_entity'] = $entity;
$build['#panelizer_bundle'] = $bundle;
$build['#panelizer_entity_id'] = $entity_id;
}
$recursion_prevention[$entity_type][$entity_id][$view_mode] = FALSE;
}