I make this a feature request since I haven't been able to have it work with the Profiles 2 module.

Comments

Andre-B’s picture

+1
subscribe

dave reid’s picture

Title: Make this compatible with Profiles 2 module » Add support for Profile 2
Version: 7.x-1.0-beta1 » 7.x-1.x-dev
Component: Miscellaneous » Code

I don't use profile2, so I would need someone else to write the patch for it, but then I can at least review it from a code level.

jaxpax’s picture

I'm sorry I can't be of any help there. I would, but I can't.

oystercrackher’s picture

+1

dave reid’s picture

I just committed the concept of 'Controllers' for complete profile, so that the logic for 'does this user have any fields that are empty' and 'give me the form fields for the user to fill out' is abstracted and separate. It should be easy to write a Profile2CompleteProfileController for someone familiar with the profile2 code base.

achikas’s picture

+1

moehac’s picture

+1

aitala’s picture

It would be a useful addition.

Eric

dave reid’s picture

Hey everyone, rather than adding more +1s and comments that this would be useful, you can use the big subscribe button at the top right of this issue, without needing to add a comment. No need to add more noise and e-mails unless we're actually making progress on this issue.

poukram’s picture

I try to write a Profile2CompleteProfileController. I just test few things and it's work for me.
I'm not an expert in profile2, maybe I've done silly things.

we have to add this in complete_profile.module

/**
 * Implements hook_complete_profile_controller() on behalf of profile2 module.
 */
function profile2_complete_profile_controller() {
  $info = array();
  $info['profile2'] = 'Profile2CompleteProfileController';
  return $info;
}

and this in complete_profile.info

files[] = includes/Profile2CompleteProfileController.php

a new file to add in includes directory => Profile2CompleteProfileController.php
and the content :


class Profile2CompleteProfileController implements CompleteProfileControllerInterface {

  public static function hasEmptyRequiredFields($account) {
    $profiles = profile2_load_by_user($account);
    foreach ($profiles as $profile) {
      if (EntityCompleteProfileController::hasEmptyRequiredFields('profile2', $profile)) {
        return TRUE;
      }
    }
    return FALSE;
  }

  public static function getFieldsForm($account, array &$form_state) {
    $form = array();

    $profiles = profile2_load_by_user($account);
    $form_state['profiles'] = $profiles;

    profile2_attach_form($form, $form_state);

    // Determine if each profile field should actually be shown or not.
    foreach ($profiles as $profile) {
      list(, , $bundle) = entity_extract_ids('profile2', $profile);
      $instances = field_info_instances('profile2', $bundle);

      foreach ($instances as $instance) {
        // Only check required and empty fields.
        $field = field_info_field($instance['field_name']);
        if (empty($instance['required']) || !EntityCompleteProfileController::isFieldEmpty('profile2', $profile, $field)) {
          $form['profile_' . $profile->type][$instance['field_name']]['#access'] = FALSE;
        }
      }
    }

    return $form;
  }
}

stewart.adam’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new4.36 KB

Attached patch (against 7.x-1.x git) adds a new module complete_profile_profile2 that adds support for profile 2.

It is based on poukram's code in the previous comment, however I have made a few modifications as my use case required that each profile type be placed in a collapsible fieldset. I also have modified it to to use profile2_category_access() so that if a user has required fields on a profile but has not yet entered any data at all, this will pick up on that and have them complete it. Previously, the code would only detect incomplete fields in existing profile entities.

sayela’s picture

Hi stewart.adam,

Thank you very much for the effort. Your solution somehow did not trigger the Complete your profile warning for required profile2 fields until I added a new required field to the default user account settings. Please is this normal or I missed something?

stewart.adam’s picture

It worked for me without having to re-save the profile type, but it's quite possible I missed something. I'll do some testing to verify if I can reproduce your issue locally.

System Lord’s picture

This seems to work. However, when a user clicks their one-time-login the first thing that come up is the empty required fields. Then once they save those entries they are taken to the "Account" page. This seems/feels backwards. I was expecting normal behavior through setting password, then after "Save" users would be directed to Complete Profile. I could except this i suppose, with additional instructions in their "one-time-login" email. But, I think all would flow naturally, and without additional instructions, if Complete Profile occurred after setting and saving the password.

I don't suppose there's a simple fix/adjustment?

ronaldmulero’s picture

Assigned: Unassigned » ronaldmulero
StatusFileSize
new1.08 KB

Excellent idea System Lord - Mark (comment #14).
Adding 'user/*/edit*' to the exclude paths array in line 124 of the complete_profile.module fixes this.

Here's the patch.
Created with git format-patch

Andre-B’s picture

Assigned: ronaldmulero » Unassigned

@ronaldmulero do not assign yourself to the ticket unless you can test, review and commit this one by yourself.

System Lord’s picture

I was rereading my #14 over and over trying to remember what the heck? My site doesn't flow this way. Then I remembered I am using project/email_registration (now). This module puts the password fields in the registration form. So, now after the user clicks the one-time-login they are presented with required fields and they don't need to be directed to the user account page to set password.

Now I'm wondering if your "fix" patch will interfere with this flow lol (?)

Mark

ronaldmulero’s picture

@Andre-B
I got carried away. :o)

@system-lord-mark
Since your users wouldn't be redirected to user/*/edit* after clicking their one-time-login link, I believe the required fields would still be presented as before.

On the other hand, if users were to type "user/[theirusernumber]/edit" into their browser address bar at any time after using their one-time-login link, they would still be able to access their account edit page.

asb’s picture

How are the chances to get #11 commited to dev?

user654’s picture

.

user654’s picture

I tried patch from #11 and enabled the new module (Complete profile-profile 2).
However I cannot make it work,even after adding a new required field.
Am I missing something?Shall I attach the profile to a role so as this works?If so,how?
I am also using Email registration module.Could this be the reason not working?
thanks

System Lord’s picture

I'm using Email registration and mine works fine. Patch #11 should be what you need with #15 patched after.

"Shall I attach the profile to a role..." Since CP works after registration I'd imagine you already have a role assigned at that point. (or explain what you mean by this)

If your using #15 make sure you haven't enabled "bypass" in permissions.

user654’s picture

.

System Lord’s picture

Actually I don't think it matters. I thought #15 made a change to #11 but it doesn't. They're independent of each other.

As for you second paragraph...This is where "Bypass complete profile module" permissions come in handy. Just check the roles you want to exclude from this module.

user654’s picture

.

System Lord’s picture

Yep, I forgot it was also a patch.

https://www.drupal.org/node/1942562

user654’s picture

.

System Lord’s picture

That I can't help you with. I do all my patching manually so I don't know what that command line does. Based on everything you have described you need to apply the patch in #26 and check the roles you want CP to bypass.

Or is CP not working at all with any roles and any required fields?

System Lord’s picture

Maybe run updates and also test on a new account (?)

user654’s picture

.

user654’s picture

.

antonyanimator’s picture

Status: Needs review » Reviewed & tested by the community

#11 worked for me great.
Just remeber that the patch results in the need to enable a sub module

Complete profile: Profile 2 integration
user654’s picture

.

antonyanimator’s picture

Pretty straightforward, when you edit a profile2 type but you shouldn't be asking that in this issue queue as its not relevant.

spanners’s picture

Having no luck with the user being asked to fill in the Profile2 fields. I applied patch #11, enabled the profile2 support module and after no luck, also applied patch #15. I'm using the dev version of this module.

  • User creates profile using HybridAuth Social login
  • Rules populates the fields that it can with the social profile selected (Facebook, Twitter or LinkedIn)
  • User is successfully redirected to complete the rest of the core User fields they need to complete
  • HybridAuth redirects them to /user page

But the user is never prompted to complete the Profile2 fields (I have three different profile types, all with unique, required fields).

I even tried putting the profile2 fields in a collapsable field set. No difference.

I checked the permissions and each role/profile type has permissions to View own profile, View any profile and Edit own profile.

Am I missing something? Or am I just out of luck because it doesn't work with HybridAuth?

chrisrockwell’s picture

Patch in #11 applied to -dev works well for me. I'm wondering if this module would be better in complete_profile/contrib/ instead of being stand-alone?

chrisrockwell’s picture

@Spanners, what happens when the user logs out (after completing required fields on core User) and then logs back in - are they then taken to user/[uid]/complete-profile?