Skip to content

Instantly share code, notes, and snippets.

@NikLP
Created October 22, 2015 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NikLP/4a2b3aa5359017359b29 to your computer and use it in GitHub Desktop.
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
/*
* 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