Created
February 28, 2015 14:07
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: