I have a registration path setup which auto assigns a user role.

It works fine in the beta3 version but when I add an alias for this url ( admin/config/search/path ) the registering user doesn't get the role assigned.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

scuba_fly’s picture

If I'm correct this could be fixed by changing
line 463 - 467 of profile2_regpath.module :

  if (!$profile_types && ($menu_item['path'] == 'system/ajax' || $menu_item['path'] == 'file/ajax')) {
    $url = drupal_parse_url($form['#action']);
    $path = end(explode('/', str_replace('/register', '', $url['path'])));
    $profile_types = profile2_regpath_get_profiles($path);
  }

To also let it check the url aliases table and search for '/register'

As I think it now does not check the url alias pad because it doesn't contain 'register'

edit: no that's not working, because the $path that is checked ( the alias ) is non existing in the regpath module.
So we need to get the alias path(s) and if one of them is used and then check the 'original' path.
Or: don't check the $url['path'] but the internal path if that's possible.

scuba_fly’s picture

Assigned: Unassigned » scuba_fly

Think this will fix it. I'll create a patch in my next post.

/**
 * Implements hook_form_alter().
 */
function profile2_regpath_form_alter(&$form, &$form_state, $form_id) {
  $menu_item = menu_get_item();
  // Check to see if we're building this form for a block.
  if (strpos($form_id, 'profile2_regpath_form_block_') === 0) {
    $profile_types = profile2_regpath_get_profiles(NULL, NULL, $form_state['profile_type_id']);
    profile2_regpath_attach_profile_fields($form, $form_state, $form_id, $profile_types);
  }
  elseif ($form_id == 'user_register_form') {
    // Get profile2 profile types from current path.
    $url = drupal_parse_url($form['#action']);
    $url = profile2_regpath_check_alias($url);
    $path = explode('/', str_replace('/register', '', $url['path']));
    $path_key = end($path);
    $profile_types = profile2_regpath_get_profiles($path_key);
    profile2_regpath_attach_profile_fields($form, $form_state, $form_id, $profile_types);
  }
}

/**
 * Helper function to load alias paths.
 */
function profile2_regpath_check_alias($url) {
  $alias = ltrim($url['path'], '/');
  $query = db_select('url_alias', 'u')
    ->fields('u',array('source'))
    ->condition('alias', $alias);
  $result = $query->execute()->fetchField();
  if($result) {
    $url['path'] = $result;
  }
  return $url;
}
scuba_fly’s picture

Version: 7.x-2.0-beta3 » 7.x-2.x-dev
FileSize
2.87 KB

Created a patch against the dev version but I think the beta3 version is the same at the moment so it should work for that as well.

grasmash’s picture

Status: Active » Fixed

Thanks for point this out.

There's no need to create profile2_regpath_check_alias(). We can use drupal_lookup_path().

Pushed commit up to dev.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.