When using several profile types for different types of users, it would make sense to show only the relevant profile fieldset to each type of users. Being able to direct them to a special registration form, using a custom path, looks like a straightforward way to do so.

This was an option using Profile2 Registration Path for D7 but it doesn't seem like a port to D8 is under way...

Would this need be common enough to users of Profile for this feature to be included in the Profile module itself, or should it remain in a dedicated module?

Comments

juliencarnot created an issue. See original summary.

mglaman’s picture

Perhaps we can include this in Profile. We currently limit profile types by role. The real problem is that the user register form does not allow you to say "I want this person to register for X role", which would be the end solution here.

We need to decide if that would live here, or something like "user_register_advanced".

Needless to say, lets research what porting profile2_regpath into the module would look like.

juliencarnot’s picture

Thanks @mglaman for your quick answer and interesting perspective: I was thinking I'd use a single role with different profile types, as that seemed to fit my needs now, but it would make sense to have separate roles for more flexibility in permissions management...

In that case, maybe the Auto Assign Role module is the solution I've been looking for? Just asked for a status update of its port...

Or would you suggest opening an issue to explore a path feature for roles registration directly in core?

itamair’s picture

I subscribe. From a very brief overview of this D8 module, indeed it is seems this is lacking the user profile registration path, (that in D7 was guaranteed by the Profile2 Registration Path module) ...

kpv’s picture

Status: Active » Needs review

Try using #2845570: Add profile form visibility settings per account (registration) form display mode together with one of the modules: form_mode_control or form_mode_manager. Both modules provide some options to switch form display mode (though I haven't tested them with registration form), which seems to be the only part needed to get the result. But anyway, with the issue mentioned above fixed the only task is to get registration (actually account) form to switch it's display mode which is not connected to the Profile module.

kpv’s picture

Or even better, instead of using contrib modules from #5 you can just add to your custom module my_module.routing.yml something like this:

my_module.register_type1:
  path: '/user/register-type1-path'
  defaults:
    _entity_form: 'user.type1_mode'
    _title: 'Create new account'
  requirements:
    _access_user_register: 'TRUE'
my_module.register_type2:
  path: '/user/register-type2-path'
  defaults:
    _entity_form: 'user.type2_mode'
    _title: 'Create new account'
  requirements:
    _access_user_register: 'TRUE'

where type1_mode and type2_mode are machine names of your custom user form display modes

also you will need to implement the following hooks:

/**
 * Implements hook_entity_type_build().
 */
function my_module_entity_type_build(array &$entity_types) {
  $entity_types['user']->setFormClass('type1_mode', 'Drupal\user\RegisterForm');
  $entity_types['user']->setFormClass('type2_mode', 'Drupal\user\RegisterForm');
}

/**
 * Implements hook_form_alter().
 */
function my_module_form_alter(&$form, $form_state, $form_id) {
  switch($form_id) {
    case 'user_type1_mode_form' :
    case 'user_type2_mode_form' :
      profile_form_user_register_form_alter($form, $form_state);
      break;
  }
}
nedjo’s picture

Status: Needs review » Active

No patch, so setting back to active.

kpv’s picture

Status: Active » Needs review

So, instead of making a custom solution (as described in #6) you can try using Registration types together with Field Permissions and avoid using Profile until #2864308: Expose profiles to all form modes is resolved.

dzy’s picture

I tried the patch and create custom module, the profile_form_user_register_form_alter() not working, profile field not show up.
it worked.

mglaman’s picture

Status: Needs review » Active

There's no patch.

geek-merlin’s picture

Status: Active » Closed (works as designed)

So we have at least 2 modules that provide this:
* Multiple Registration | Drupal.org
* Registration types | Drupal.org

so i'd say if something is needed, we need more specific integration issues.