function user_relationships_ui_form_alter in User Relationships 7
Implements hook_form_alter().
File
- user_relationships_ui/
user_relationships_ui.module, line 505 - UI components of user_relationships @author Jeff Smick (creator) @author Alex Karshakevich (maintainer) http://drupal.org/user/183217 @author Darren Ferguson (contributor) http://drupal.org/user/70179
Code
function user_relationships_ui_form_alter(&$form, &$form_state, $form_id) {
if (($form_id == 'user_register_form' || $form_id == 'user_profile_form') && $form['#user_category'] == 'account') {
// Create array to be able to merge in fieldset and avoid overwriting
// already added options.
if (!isset($form['user_relationships_ui_settings'])) {
$form['user_relationships_ui_settings'] = array();
}
// Always create the fieldset in case other modules want to add
// related settings through hook_form_alter(). If it's still empty after the
// build process, the after build function will remove it.
$form['user_relationships_ui_settings'] += array(
'#type' => 'fieldset',
'#title' => t('Relationships'),
'#weight' => 5,
'#collapsible' => TRUE,
'#after_build' => array(
'user_relationships_ui_account_fieldset_remove_if_empty',
),
);
if (variable_get('user_relationships_ui_require_approval', TRUE)) {
if (variable_get('user_relationships_allow_auto_approve', FALSE) && ($relationships = user_relationships_types_load())) {
if (!isset($form['#user']->data['user_relationships_ui_auto_approve']) || !is_array($form['#user']->data['user_relationships_ui_auto_approve'])) {
$form['#user']->data['user_relationships_ui_auto_approve'] = array();
}
$options = array();
foreach ($relationships as $relationship) {
if ($relationship->requires_approval && user_relationships_ui_check_access('approve', NULL, $relationship)) {
$options[$relationship->rtid] = user_relationships_type_get_name($relationship);
}
}
//#453090 Do nothing if there are no options.
if (count($options)) {
$form['user_relationships_ui_settings']['user_relationships_ui_auto_approve'] = array(
'#type' => 'checkboxes',
'#title' => t('Automatically approve relationship requests from other users'),
'#options' => $options,
'#default_value' => $form['#user']->data['user_relationships_ui_auto_approve'],
'#description' => t("When another user requests a relationship with you, we usually require your approval. If you'd like certain relationship types to be approved automatically, check the box next to that type."),
);
}
}
}
}
}