function notifications_user_form in Notifications 6.2
Same name and namespace in other branches
- 5 notifications.admin.inc \notifications_user_form()
- 6.4 notifications.module \notifications_user_form()
- 6 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
3 string references to 'notifications_user_form'
- notifications_content_page_author in notifications_content/
notifications_content.pages.inc - User subscriptions to content types
- notifications_content_page_nodetype in notifications_content/
notifications_content.pages.inc - User subscriptions to content types
- notifications_content_page_thread in notifications_content/
notifications_content.pages.inc - Subscriptions page callback: List thread subscriptions
File
- ./
notifications.module, line 1626 - Notifications module
Code
function notifications_user_form($form_state, $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,
), array(), FALSE, 'value');
}
$defaults += array(
'sid' => 0,
'type' => $type,
'event_type' => $info['event_type'],
);
$defaults += _notifications_subscription_defaults($account);
// Hide Send method column if only one
$send_methods = _notifications_send_methods();
$header = array(
theme('table_select_header_cell'),
$field_title,
t('Send interval'),
);
if (count($send_methods) > 1) {
$header[] = t('Send method');
}
$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' => $header,
);
$send_intervals = notifications_send_intervals();
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' => $send_intervals,
'#default_value' => $rowdefaults['send_interval'],
);
// Hide send methods if only one available
if (count($send_methods) > 1) {
$form['subscriptions']['send_method'][$key] = array(
'#type' => 'select',
'#options' => _notifications_send_methods(),
'#default_value' => $rowdefaults['send_method'],
);
}
else {
$form['subscriptions']['send_method'][$key] = array(
'#type' => 'value',
'#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;
}