Skip to content

Instantly share code, notes, and snippets.

@msupko
Last active August 29, 2015 14:00
Show Gist options
  • Save msupko/11376946 to your computer and use it in GitHub Desktop.
Save msupko/11376946 to your computer and use it in GitHub Desktop.
Adding User Profile Fields to Bakery for Drupal 7
<?php
/**
* Admin settings, see INSTALL.txt
*/
function bakery_settings($form, &$form_state) {
$form = array(
'#submit' => array('bakery_settings_submit'),
);
$form['bakery_is_master'] = array(
'#type' => 'checkbox',
'#title' => 'Is this the master site?',
'#default_value' => variable_get('bakery_is_master', 0),
'#description' => t('On the master site, accounts need to be created by traditional processes, i.e by a user registering or an admin creating them.'),
);
$form['bakery_master'] = array(
'#type' => 'textfield',
'#title' => 'Master site',
'#default_value' => variable_get('bakery_master', 'http://drupal.org/'),
'#description' => t('Specify the master site for your bakery network.'),
);
$form['bakery_slaves'] = array(
'#type' => 'textarea',
'#title' => 'Slave sites',
'#default_value' => implode("\n", variable_get('bakery_slaves', array())),
'#description' => t('Specify any slave sites in your bakery network that you want to update if a user changes email or username on the master. Enter one site per line, in the form "http://sub.example.com/".'),
);
$form['bakery_help_text'] = array(
'#type' => 'textarea',
'#title' => 'Help text for users with synch problems.',
'#default_value' => variable_get('bakery_help_text', 'Otherwise you can contact the site administrators.'),
'#description' => t('This message will be shown to users if/when they have problems synching their accounts. It is an alternative to the "self repair" option and can be blank.'),
);
$form['bakery_freshness'] = array(
'#type' => 'textfield',
'#title' => 'Seconds of age before a cookie is old',
'#default_value' => variable_get('bakery_freshness', '3600'),
);
$form['bakery_key'] = array(
'#type' => 'textfield',
'#title' => 'Private key for cookie validation',
'#default_value' => variable_get('bakery_key', ''),
);
$form['bakery_domain'] = array(
'#type' => 'textfield',
'#title' => 'Cookie domain',
'#default_value' => variable_get('bakery_domain', ''),
);
$default = variable_get('bakery_supported_fields', array('mail' => 'mail', 'name' => 'name'));
$default['mail'] = 'mail';
$default['name'] = 'name';
$options = array('name' => t('username'), 'mail' => t('e-mail'), 'status' => t('status'), 'picture' => t('user picture'), 'language' => t('language'), 'signature' => t('signature'),);
$result = field_info_instances('user');
foreach ($result['user'] as $field => $data) {
$options[$field] = check_plain($data['label']);
}
$form['bakery_supported_fields'] = array(
'#type' => 'checkboxes',
'#title' => 'Supported profile fields',
'#default_value' => $default,
'#options' => $options,
'#description' => t('Choose the profile fields that should be exported by the master and imported on the slaves. Username and E-mail are always exported. The correct export of individual fields may depend on the appropriate settings for other modules on both master and slaves. You need to configure this setting on both the master and the slaves.'),
);
// Tell system_settings_form() to not set default_values since we have already done so.
return system_settings_form($form, FALSE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment