1

As you may know, there's one single permission that controls user's access to other user's creation - permission is called 'administer users'. It either gives access to full user's administration or to nothing.

On my system I have tiered users who are supposed to have some permissions in relation to user administration. But not all permissions. I basically need to be able to create user accounts (based on profile2) on the frontend url (not /admin/people/p2rp-create/user but eg. /add-user.

I know there's a way of rendering an existing Drupal registration form, not sure how to a) render profile2 form, or, to be precise, render profile2 form that includes forms for few created profile (I have 3 at the moment) b) make it create a user even tho user doesn't have 'administer user'

I played with the following for starters

function module_menu(){
  $items['add-user'] = array(
  'title' => 'Add user',
  'page callback' => 'module_reg_form',
  'access arguments' => array('access create customer'),
 );

function module_reg_form(){
  $user_register_form = drupal_get_form('user_register_form');
  $form_state = array('profiles' => array('contact_details'));
  $registration_with_profile_fields_form = profile2_attach_form($user_register_form, $form_state);
  print(drupal_render($user_register_form));
}

This throws an error

EntityMalformedException: Missing bundle property on entity of type profile2. in entity_extract_ids() (line 7721 of /home/dreamweddings/www/dreamweddings.eu/public/includes/common.inc).

1 Answer 1

1

Can you not simply give user permissions to create users of specific roles (via the administerusersbyrole module) and then use the existing user creation form at /admin/people/create? If you do go with administerusersbyrole, make sure you follow the two steps on the project page for assigning the configuration.

If you must have a custom form via another page, you probably want to do it via a proper form definition function by setting the menu 'page callback' to 'drupal_get_form', and then passing the function that provides the form definition in 'page arguments'. See this particular comment for a code example. This way you'll be able to do proper form validation and a for submit handler too. Even if you get your current snippet working, the form still needs to submit somewhere to work.

3
  • I'm using profile2 and have different registration forms depending on the user type (different registration forms for a customer, different for a sales person). So that module won't help. I'm thinking my only way to approach this for now would be to control access to other backend user related pages in hook_menu?
    – belinea
    Commented Mar 26, 2014 at 9:29
  • Have you seen profile2_regpath already? You could use that, and perhaps do a hook_menu_alter() on the menu items defined in profile2_regpath to control who can create which types of users. Hope that can help.
    – alexkb
    Commented Mar 26, 2014 at 10:05
  • Yeah, I'm using this module. Will try controlling the access with menu_alter()
    – belinea
    Commented Mar 26, 2014 at 10:39

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.