function notifications_user_form in Notifications 5
Same name and namespace in other branches
- 6.4 notifications.module \notifications_user_form()
- 6 notifications.module \notifications_user_form()
- 6.2 notifications.module \notifications_user_form()
- 6.3 notifications.module \notifications_user_form()
Generic subscriptions content form
Builds a form for a user to manage its own subscriptions with some generic parameters
Currently it only manages simple condition fields
Parameters
$account : User account
$type: Subscription type
$subscriptions: Current subscriptions of this type. If null they'll be loaded
$list: Array with available subscriptions indexed by field value
$defaults: Default value for subscriptions
$options: Optional, array of aditional options for the form
4 string references to 'notifications_user_form'
- notifications_content_page_author in notifications_content/
notifications_content.module - User subscriptions to content types
- notifications_content_page_nodetype in notifications_content/
notifications_content.module - User subscriptions to content types
- notifications_content_page_thread in notifications_content/
notifications_content.module - Subscriptions page callback: List thread subscriptions
- notifications_feed_user_page in notifications_feed/
notifications_feed.module - Menu callback. User subscriptions to groups.
File
- ./
notifications.admin.inc, line 566
Code
function notifications_user_form($account, $type, $subscriptions, $list, $defaults, $options = array()) {
// Complete defaults
$info = notifications_subscription_types($type);
$field = $info['fields'][0];
$field_title = !empty($options['title']) ? $options['title'] : '';
if (is_null($subscriptions)) {
// Fetch subscriptions with given parameters
$subscriptions = notifications_get_subscriptions(array(
'type' => $type,
'event_type' => $info['event_type'],
'uid' => $account->uid,
), TRUE, 'value');
}
$defaults += array(
'sid' => 0,
'type' => $type,
'event_type' => $info['event_type'],
);
$defaults += _notifications_subscription_defaults($account);
$form['defaults'] = array(
'#type' => 'value',
'#value' => $defaults,
);
$form['account'] = array(
'#type' => 'value',
'#value' => $account,
);
$form['current'] = array(
'#type' => 'value',
'#value' => $subscriptions,
);
$form['subscription_fields'] = array(
'#type' => 'value',
'#value' => array(),
);
$form['subscriptions'] = array(
'#tree' => TRUE,
'#theme' => 'notifications_form_table',
'#header' => array(
theme('table_select_header_cell'),
$field_title,
t('Send interval'),
t('Send method'),
),
);
foreach ($list as $key => $title) {
$rowdefaults = isset($subscriptions[$key]) ? (array) $subscriptions[$key] : $defaults;
$rowdefaults += $rowdefaults;
$form['subscriptions']['checkbox'][$key] = array(
'#type' => 'checkbox',
'#default_value' => $rowdefaults['sid'],
);
$form['subscriptions']['title'][$key] = array(
'#value' => $title,
);
$form['subscriptions']['send_interval'][$key] = array(
'#type' => 'select',
'#options' => _notifications_send_intervals(),
'#default_value' => $rowdefaults['send_interval'],
);
$form['subscriptions']['send_method'][$key] = array(
'#type' => 'select',
'#options' => _notifications_send_methods(),
'#default_value' => $rowdefaults['send_method'],
);
// Pass on the fields for processing
$form['subscription_fields']['#value'][$key] = array(
$field => $key,
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}