Skip to content

Instantly share code, notes, and snippets.

@amcgowanca
Created February 28, 2015 14:07
Show Gist options
  • Save amcgowanca/77c8ba4b8c2fe6fba3a9 to your computer and use it in GitHub Desktop.
Save amcgowanca/77c8ba4b8c2fe6fba3a9 to your computer and use it in GitHub Desktop.
Drupal 7: Bean view page override with bean type specific page view callback.
<?php
/**
* Implements hook_menu_alter().
*/
function MODULE_menu_alter(&$items) {
if (isset($items['block/%bean_delta'])) {
$items['block/%bean_delta']['page callback'] = 'MODULE_bean_view_page';
}
}
/**
* Bean view page.
*/
function MODULE_bean_view_page(Bean $bean) {
$title = $bean->label() ? $bean->label() : $bean->adminTitle();
drupal_set_title($title);
if ($module = $bean->getInfo('module')) {
$page_callback = $module . '_bean_' . $bean->type . '_view_page';
if (function_exists($page_callback)) {
return $page_callback($bean);
}
}
return bean_view($bean);
}
@amcgowanca
Copy link
Author

The origin of this code is from the use case in which the selected view mode value is not actually set or used with a default bean view on the bean view page. Therefore, an example implementation of the hook_bean_BEAN_TYPE_view_page would be:

function MODULE_bean_BEAN_TYPE_view_page(Bean $bean) {
  return $bean->view($bean->view_mode, $GLOBALS['language_content']->language);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment