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
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
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.
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.
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.
This is a known issue it seems with Panels2. Overrides can still be done with the default Drupal template engine.
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.
There is a patch here to provide the missing glue between Panels and Profile2.
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.