Currently I need to use following code:

/**
 * Implements hook_views_post_execute().
 */
function example_views_post_render($view, &$output, &$cache) {
  if (arg(0) == 'crm' && arg(1) == 'contact' && arg(2) != '' ) {
    $contact = crm_core_contact_load(arg(2));
    $view->set_title(t(crm_core_contact_title($contact)));
  }
}

This happens because it is not possible to do the same in Views. When clicking on "Override title" and embedding there "%1" we are having id instead of contact name.

CommentFileSizeAuthor
#2 Override Title #2.png116.3 KBpdcrane
#2 Override Title #1.png113.6 KBpdcrane

Comments

Anonymous’s picture

Status: Active » Closed (works as designed)

Yeah, this is really a limitation of views more than anything. Addressed in CRM Core through some preprocessing functions.

pdcrane’s picture

Issue summary: View changes
StatusFileSize
new113.6 KB
new116.3 KB

Just for those looking for a similar solution. I implemented this using the Views UI on a view with contextual filters (a views replacement for crm-core/contact/%1/view)

In Views 3:

  1. First select contextual filter and filter by CRM Contact: Contact ID. Remember to select Provide Default Value "Content ID from URL" under When Filter Value is not in the URL.
  2. Then check Override Title but leave blank
  3. Then specify validation criteria and select PHP Code
  4. Enter the code below:
if($argument) { // Check that argument is present
  $myContact = crm_core_contact_load($argument);
  $newTitle = crm_core_contact_title($myContact);
  $handler->options['title'] = $newTitle;
}
return true;

Do not include tags