Index: autoassignrole.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/autoassignrole/autoassignrole.module,v
retrieving revision 1.9.2.14
diff -u -p -r1.9.2.14 autoassignrole.module
--- autoassignrole.module 11 May 2009 21:23:36 -0000 1.9.2.14
+++ autoassignrole.module 31 May 2009 12:07:52 -0000
@@ -141,8 +141,6 @@ function autoassignrole_perm() {
function autoassignrole_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case 'insert':
- $path = drupal_get_path_alias($_GET['q']);
- $page = db_fetch_object(db_query("SELECT rid FROM {autoassignrole_page} WHERE path = '%s'", $path));
if (_autoassignrole_settings('user_active') == 1) {
$roles = array();
$user_roles = _autoassignrole_settings('user_roles');
@@ -158,8 +156,8 @@ function autoassignrole_user($op, &$edit
$edit['roles'] = array($edit['user_roles'] => $edit['user_roles']);
}
}
- if (isset($page->rid)) {
- $edit['roles'][$page->rid] = $page->rid;
+ if ($rid = autoassignrole_get_active_path_rid()) {
+ $edit['roles'][$rid] = $rid;
}
if (_autoassignrole_settings('auto_active') == 1) {
$auto_roles = _autoassignrole_settings('auto_roles');
@@ -372,48 +370,63 @@ function _autoassignrole_array_asc($a, $
return ($a > $b) ? -1 : 1;
}
+/**
+ * Implementation of hook_form_alter().
+ *
+ * Integrate with content profile's registration integration
+ */
function autoassignrole_form_alter(&$form, $form_state, $form_id) {
- if ($form_id == 'node_type_form' && module_exists('content_profile')) {
+ if ($form_id == 'content_profile_admin_settings') {
+ $type = $form_state['type'];
$result = db_query("SELECT ar.path, ar.rid, r.name FROM {autoassignrole_page} ar INNER JOIN {role} r ON ar.rid = r.rid");
$options = array();
- $options[0] = "All Registration forms";
while ($r = db_fetch_object($result)) {
- $options[$r->rid] = "($r->name) $r->path";
+ $options[$r->rid] = filter_xss_admin("($r->name) $r->path");
}
- $form['content_profile']['aar'] = array(
- '#type' => 'radios',
- '#title' => 'Path',
- '#default_value' => variable_get('autoassignrole_content_profile_'. $form['#node_type']->type, 0),
+ $form['registration']['autoassignrole_use'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Use on Auto Assign Role paths'),
+ '#default_value' => content_profile_get_settings($type, 'autoassignrole_use'),
'#options' => $options,
- '#description' => t('The Auto Assign Role module gives you the ability to
- assign paths a user can register from for a role. After associating a path with a role your selection can associate this content type with a path.', array('@aar' => url('admin/user/autoassignrole'))),
+ '#description' => t('The Auto Assign Role module gives you the ability to assign paths a user can register from for a role. After associating a path with a role your selection can associate this content type with a path.', array('@aar' => url('admin/user/autoassignrole'))),
+ '#disabled' => count($options) == 0,
+ '#weight' => 3,
);
- $form['#submit'][] = 'autoassignrole_node_type_form_submit';
+ array_unshift($form['#submit'], 'autoassignrole_content_profile_admin_form_submit');
}
- if ($form_id == 'user_register' && module_exists('content') && module_exists('content_profile')) {
- $profile_types = content_profile_get_types('names', 'registration_use');
- $path = drupal_get_path_alias($_GET['q']);
- if ($path != '/user/register') {
- $page = db_fetch_object(db_query("SELECT rid FROM {autoassignrole_page} WHERE path = '%s'", $path));
- if (isset($page->rid)) {
- foreach ($profile_types as $type => $typename) {
- $enabled = variable_get('autoassignrole_content_profile_'. $type, 0);
- if ($enabled != $page->rid) {
- $node = array('uid' => 0, 'name' => '', 'type' => $type);
- $node_form = drupal_retrieve_form($type .'_node_form', $form_state, $node);
- drupal_prepare_form($type .'_node_form', $node_form, $form_state);
- foreach ($node_form['#field_info'] as $field_name => $info) {
- unset($form[$field_name]);
- }
- }
+ elseif ($form_id == 'user_register' && module_exists('content_profile_registration')) {
+ if (implode('/', arg()) != 'user/register' && $rid = autoassignrole_get_active_path_rid()) {
+ // Set the content types which should be shown by the content_profile_registration module
+ $form['#content_profile_registration_use_types'] = array();
+ foreach (content_profile_get_types('names') as $type => $name) {
+ if (in_array($rid, content_profile_get_settings($type, 'autoassignrole_use'))) {
+ $form['#content_profile_registration_use_types'][$type] = $name;
}
}
}
}
}
-function autoassignrole_node_type_form_submit($form, &$form_state) {
- variable_set('autoassignrole_content_profile_'. $form['#node_type']->type, $form_state['values']['aar']);
- return;
+function autoassignrole_content_profile_admin_form_submit($form, &$form_state) {
+ $form_state['values']['autoassignrole_use'] = array_keys(array_filter($form_state['values']['autoassignrole_use']));
+}
+
+/**
+ * Implementation of hook_content_profile_settings().
+ */
+function autoassignrole_content_profile_settings() {
+ return array(
+ 'autoassignrole_use' => array_keys(user_roles((TRUE))),
+ );
}
+/**
+ * Returns the role id of the currently active AAR-path.
+ */
+function autoassignrole_get_active_path_rid() {
+ $item = menu_get_item();
+ if ($item['page_callback'] == 'autoassignrole_path') {
+ return $item['page_arguments'][0];
+ }
+ return FALSE;
+}