Created
October 22, 2015 15:16
-
-
Save NikLP/4a2b3aa5359017359b29 to your computer and use it in GitHub Desktop.
Profile2 "profile page" title set using entity_metadata_wrapper in hook_entity_view
This file contains 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
/* | |
* Implementation of hook_entity_view | |
*/ | |
function helpermodule_entity_view($entity, $type, $view_mode, $langcode) { | |
// we're viewing an entity | |
// check if it's a profile2 type | |
// - if there's more than one profile2, check for that too! | |
// - and the view mode is 'page' (not 'full', for profile2 it seems) | |
if ($type == 'profile2' && $entity->type == 'member' && $view_mode == 'page') { | |
// get an entity metadata wrapper for easy access to data | |
// pass in the profile2 type and the profile id | |
$wrapper = entity_metadata_wrapper('profile2', $entity->pid); | |
// set the page title to the member name field value | |
// also changes the breadcrumb automatically | |
// (in easy_breadcrumbs, at least) but not page title | |
drupal_set_title($wrapper->field_member_name->value()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment