2

I'm rendering a user customer profile in a form using the code:

$profile = profile2_load_by_user($account, 'customer');
$form['customer_profile'] = array(
    '#type' => 'item',
    '#markup' => render($profile->view('block')),
);

which works rather well, except that the title (in H2 tags) is rendered as a link back to the profile.

I want to get rid of that link, but as there seems to be no obvious property, to specify if you do or do not want a backlink. Not in the $build array parameter of hook_entity_view_alter, nor in the $elements parameter for a '#pre_render' callback. In a '#post_render' callback, it's too late because the link is already inserted into html.

So, how do I get rid of it?

2

This link is part of template file profile2.tpl.php defined as $title and it appear for non page display modes as described by the template code.

<?php if (!$page): ?>
<h2<?php print $title_attributes; ?>>
    <a href="<?php print $url; ?>"><?php print $title; ?></a>
</h2>
<?php endif; ?>

The short possible solution can be to unset title variable implementing hook_preprocess_profile2. But to remove whole markup you will have to overwrite theme registry implementing hook_theme_registry_alter(&$theme_registry) to replace template against profile2.

$theme_registry['profile2'] = array(
  'render element' => 'elements',
  'template' => 'profile2_custom',
  'path' => path_to_theme(),
);
| improve this answer | |
  • Thanks, even though your post contains some errors (for example: hook_preprocess_profile2.tpl.php is never included, but hook_preprocess_entity.tpl.php is), you provided more than enough clues to figure something out. – bart Jul 11 '11 at 12:47
  • What I ended up doing was making a copy of profile2.tpl.php as profile2--customer--block.tpl.php, and remove the link from there. – bart Jul 11 '11 at 12:49
  • hook_preprocess_profile2() is suggested in profile2.api.php (part of profile2 module). See the definition of hook_profile2_view_alter(). I think you was expecting hook_preprocess_profile2.tpl.php as a template file. In-fact 'profile2' entry in theme registry expects a template profile2.tpl.php in module's directory. On the other hand the hook_preprocess_profile2 is invoked just before to render this template to manipulate variables in the scope of that template. :) – Shoaib Nawaz Jul 11 '11 at 13:53
0

Is it possible to get a more detailed explanation of your solution to this problem? I am having this exact problem. I would comment but I can not.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.