5

How can I override a Profile2 profile page using Panels in Drupal 7?

The page I'm looking to override is the edit for for one of the new profile2 pages. Here is an example URL: http://example.com/profile-user_settings/%uid/edit

3
  • What type of override you are looking? Commented Jun 8, 2012 at 3:26
  • I want to split the page into two columns. Left being the original content from the Profile2 edit form, right being a rendered node. Very easy to do with panels, but can't seem to snag the edit form for use.
    – Citricguy
    Commented Jun 8, 2012 at 6:49
  • I just thought to look at the Profile2 bugs. Seems there are a bunch of issues with ctools. drupal.org/project/issues/profile2?text=ctools&status=All I may have put this up on SA too quickly.
    – Citricguy
    Commented Jun 8, 2012 at 6:51

7 Answers 7

6

There is a work around using Page Manager Existing Pages (as suggested by Letharion) and hook_menu().

hook_menu() was required as Profile2 doesn't seem to register profile pages with the menu router. This was preventing Page Manager Existing Pages from being able to intercept the page.

function MYMODULE_menu() {
    $items['profile-example'] = array(
        'page callback' => '_profile2_form',
        'page arguments' => array(),
        'access callback' => TRUE,
        'type' => MENU_CALLBACK,
    );
    return $items;
}

function _profile2_form() {
    global $user;
    module_load_include('inc', 'profile2_page', 'profile2_page');
    $profile2 = profile2_by_uid_load($user->uid, 'profile2_profile_system_name_goes_here');
    $entity_form = entity_ui_get_form('profile2', $profile2, 'edit');
    return $entity_form;    
}

This can now be intercepted by Page Manager Existing Pages and properly displayed by the Panels module.

0

You can plan it with blocks using Node Block module that would help to bring any node content to configurable block for profile page.

You can also focus page-profile.tpl.php, if you are looking customization on that page regarding layout. e.g. new region placement etc.

0

I haven't looked at this, but a guess says that Profile2 will need to implement a ctools "task" for the form to become accessible like other things in the Panels UI.

In your simple use case though, you could try Page manager existing pages which will wrap an existing page for you. This should be enough for your current use case.

2
  • Couldn't get PMEP to get in early enough to grab that pre-existing URL. Will read through the docs and give it another go though.
    – Citricguy
    Commented Jun 8, 2012 at 14:43
  • Looked into this a bit more, it seems that PMEP doesn't implement hook_menu(). I'm guessing this is why there is no menu item for PMEP to hijack.
    – Citricguy
    Commented Aug 31, 2012 at 1:35
0

This is a known issue it seems with Panels2. Overrides can still be done with the default Drupal template engine.

1
0

Responding to Citricguy above, I tried a number of iterations of your great tip, but what finally worked was to, effectively, hardcode the profile2 path for each profile in our system. Ex:

$items['user/%user/edit/consumer_profile'] = array(
  'page callback' => '_profile2_form',
  'page arguments' => array(),
  'access callback' => TRUE,
  'title' => 'My Profile',
  'type' => MENU_LOCAL_TASK,
);
return $items;

The rest of your example remained true. That said, I can probably pass in the "consumer_profile" bit to your entity fetcher helper.

0

There is a patch here to provide the missing glue between Panels and Profile2.

https://drupal.org/node/1011370#comment-6884220

0

Regarding the "workaround using Page Manager Existing Pages", I assume you wouldn't want 'access callback' => TRUE, in your menu hook since anonymous users (i.e. uid = 0) wouldn't have a profile and this would result in downstream errors. I suppose you can just add

'access arguments' => array('edit own main profile'),

to the array instead to mimic pre-existing permissions for Profile2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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