0

I'm using a function[a] to get custom templates to work for all pages, including role registration pages set by Auto Assign Role. By setting the role registration path to user/register/<rolename> I'm able to use page--user--register--rolename.tpl.php to make custom pages.

enter image description here

What I'm trying to do now is use a custom user_register_form for each role registration page. Using this function[b] I'm able to use user-register-form.tpl.php to customize the registration form. This affects the form for both role pages though. I tried using the Field Permissions module, but because an anonymous user will be using both forms it's of no use here.

I'm thinking I need to change what user-register-form template the page itself is looking for, but I can't figure out how to do that.

a.

function THEMENAME_preprocess_page(&$vars) {

  if (isset($vars['node'])) {

    $suggests = &$vars['theme_hook_suggestions'];

    $args = arg();
    // Remove first argument of "node".
    unset($args[0]);

    $type = "page__type_{$vars['node']->type}";

    $suggests = array_merge(
      $suggests,
      array($type),
      theme_get_suggestions($args, $type)
    );
  }
}

b.

 function THEMENAME_theme() {
  $items = array();

  $items['user_login'] = array(
    'render element' => 'form',
    'path' => drupal_get_path('theme', 'THEMENAME') . '/templates',
    'template' => 'user-login',
    'preprocess functions' => array(
       'THEMENAME_preprocess_user_login'
    ),
  );
  $items['user_register_form'] = array(
    'render element' => 'form',
    'path' => drupal_get_path('theme', 'THEMENAME') . '/templates',
    'template' => 'user-register-form',
    'preprocess functions' => array(
      'THEMENAME_preprocess_user_register_form'
    ),
  );
  $items['user_pass'] = array(
    'render element' => 'form',
    'path' => drupal_get_path('theme', 'THEMENAME') . '/templates',
    'template' => 'user-pass',
    'preprocess functions' => array(
      'THEMENAME_preprocess_user_pass'
    ),
  );
  return $items;
}
0

I think if you already have a template file for the form user-register-form.tpl.php, you should be able to use a preprocess like this:

function MYTHEME_preprocess_user_register_form($vars) {
  // if role2
  // use other theme
}

There should be no need to define your own themes with hook_theme

  • I'm new to drupal theming (I copied those functions from elsewhere). Where would I go to learn how to build what you're describing from scratch? I can't tell if the hook_preprocess_HOOK(), hook_theme() or theme() doc page is where I should start. I think it's the first one, but I'm having trouble relating what I see on the user_register_form() page to what I'm seeing described there. – delz Jul 27 '15 at 9:23
  • maybe start with the drupal theming docs – 2pha Jul 27 '15 at 10:02
  • I looked through them but couldn't figure this out. I think the problem is this being a third party module. I need to either affect the user_register_form template being used by the path or in the module itself. AFAIK if role checks for the user's role, not the role being auto assigned. This being a registration page the role will always be anonymous. – delz Jul 28 '15 at 0:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.