Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Profile2 "profile page" title set using entity_metadata_wrapper in hook_entity_view
/*
* 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