Custom template for each profile2 profile type edit form

I am working on a Drupal 7 site and for a few days now, I’ve been struggling with this problem: I am trying to create a custom template for the edit profile form, but there are more profile types. I managed to create the template but it does not work properly. I am able to save all the fields except the image field. When I hit remove button, the filed disappears completely, then I have to hit save two times for the image to be actually removed. Also, if I add an image, then press upload, I get a warning:

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘profile2_form’ not found or invalid function name in drupal_retrieve_form() (line 841 of /var/www/html/hxl_drupal/includes/form.inc).)

If I hit save twice, the image gets saved.

I tried a lot of websites, including these:

I should also mention that the form is submitted through AJAX and that I use ctools module to open it in modal.

Below you can see the code.

template.php

/* * Implements hook_form_alter() */  function customtheme_form_alter(&$form, &$form_state, $form_id) {   if ($form_id == 'user_profile_form') {     if ($form['#user_category'] === 'partner_user') {       $form['#theme'] = 'profile2_partner_user_edit_form';     } else if ($form['#user_category'] === 'advisor_user') {       $form['#theme'] = 'profile2_advisor_user_edit_form';     }   } }  /* *implements hook_theme() */  function customtheme_theme() {   return array(     'profile2_partner_user_edit_form' => array(       'arguments' => array(         'form' => NULL,       ),       'template' => 'templates/profile2--partner-user-edit',       'render element' => 'form',     ),     'profile2_advisor_user_edit_form' => array(       'arguments' => array(         'form' => NULL,       ),       'template' => 'templates/profile2--advisor-user-edit',       'render element' => 'form'     ),   ); } 

custom_module.module

/** * hook_menu */ function custom_module_menu() { $items['profile/user-advisor_user_edit/%user/%ctools_js'] = array(   'page callback' => 'profile_advisor_user_edit',   'page arguments' => array(2,3),   'type' => MENU_CALLBACK,   'access callback' => TRUE,   'file path' => drupal_get_path('module', 'user'),   'file' => 'user.pages.inc', );  $items['profile/user-partner_user_edit/%user/%ctools_js'] = array(     'page callback' => 'profile_partner_user_edit',     'page arguments' => array(2,3),     'type' => MENU_CALLBACK,     'access callback' => TRUE,     'file path' => drupal_get_path('module', 'user'),     'file' => 'user.pages.inc',   );      return $items; } 

I will post only the code for this profile type, because except the key word advisor_user.

function profile_advisor_user_edit($user, $js = FALSE ){   if ($js){     ctools_include('user.pages', 'user', '');    ctools_include('modal');    ctools_include('ajax');      $form_state = array(    'ajax' => TRUE,    'title' => t('Edit Profile'),    'user_id' => $user,     );     $form_state['build_info'] = array(    'args' => array($user),    );     $output = ctools_modal_form_wrapper('profile2_advisor_user_edit_form', $form_state);          if (!empty($form_state['executed'])) {       $output = array();       $output[] = ctools_modal_command_dismiss();     }    print ajax_render($output);   exit; }else{   module_load_include('inc', 'user', 'user.pages');   $user_edit_form =     drupal_get_form('profile2_advisor_user_edit_form',$user);   return drupal_render($user_edit_form); } 

}

The profile2--advisor-user-edit.tpl.php file I will post the code only for this profile type because they are pretty much the same.

 module_load_include('inc', 'profile2_page', 'profile2_page'); // Include profile2_page module  $profile2 = profile2_by_uid_load($user->uid, 'advisor_user'); $entity_form = entity_ui_get_form('profile2', $profile2, 'edit'); // Or 'add' print render($entity_form['profile_advisor_user']['field_picture']); print render($entity_form['profile_advisor_user']['field_first_name']); print render($entity_form['profile_advisor_user']['field_last_name']); print render($entity_form['profile_advisor_user']['field_role']); print render($entity_form['profile_advisor_user']['field_bio']); print render($entity_form['profile_advisor_user']  ['field_interest_topics']); print render($entity_form['profile_advisor_user']['field_interest_areas']); unset($entity_form['extra_fields']) //here I unset the fields that I don't want to appear in the form print render($entity_form); 
This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Custom template for each profile2 profile type edit form

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.