function notifications_ui_options_form in Notifications 6.2
Same name and namespace in other branches
- 6 notifications_ui/notifications_ui.module \notifications_ui_options_form()
- 6.3 notifications_ui/notifications_ui.module \notifications_ui_options_form()
Form for node subscriptions @ TODO: offer the same form in a block to be put in the contents region.
Parameters
$subscriptions: Array of subscription options
$fieldset: Optional produce fieldset instead of full form
$buttons: Whether to add buttons
Return value
Partial subscription form, just missing submit button.
2 calls to notifications_ui_options_form()
- notifications_ui_account_subform in notifications_ui/
notifications_ui.module - Form for node subscriptions @ TODO: offer the same form in a block to be put in the contents region.
- notifications_ui_node_subform in notifications_ui/
notifications_ui.module - Form for node subscriptions @ TODO: offer the same form in a block to be put in the contents region.
2 string references to 'notifications_ui_options_form'
- notifications_ui_block in notifications_ui/
notifications_ui.module - Implementation of hook_block()
- notifications_ui_forms in notifications_ui/
notifications_ui.module - Implementation of hook_forms()
File
- notifications_ui/
notifications_ui.module, line 236 - User Interface for subscriptions modules
Code
function notifications_ui_options_form($form_state, $subscriptions, $fieldset = FALSE, $buttons = TRUE) {
global $user;
$form = array();
// Process all options building the array of indexed params for each
$options = $params = $defaults = array();
$index = 1;
// If we start with zero, get some value sent as 0 => 0
$number = 0;
// Number of subscriptions
foreach ($subscriptions as $option) {
$options[$index] = $option['name'];
// Check wether user is subscribed
if (!empty($option['subscription'])) {
$params[$index] = (array) $option['subscription'];
$defaults[] = $index;
$number++;
}
else {
$params[$index] = $option;
}
$index++;
}
// Now we have compiled the data, build the form. Note that we are passing the parameters
// in the 'params' value as an array, while the checkboxes are in 'options' fieldset
if ($fieldset) {
$form['subscriptions'] = array(
'#type' => 'fieldset',
'#title' => t('Subscriptions (@number)', array(
'@number' => $number,
)),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
);
}
else {
$form['subscriptions'] = array(
'#tree' => TRUE,
);
}
$form['subscriptions']['params'] = array(
'#type' => 'value',
'#value' => $params,
);
$form['subscriptions']['options'] = array(
'#type' => 'checkboxes',
'#default_value' => $defaults,
'#options' => $options,
);
$form['subscriptions']['account'] = array(
'#type' => 'value',
'#value' => $user,
);
if ($buttons) {
$form['subscriptions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Update'),
);
// If full form, redirect so the full page which may have subscription links is updated
$form['#redirect'] = $_GET['q'];
$form['#submit'] = array(
'notifications_ui_options_form_submit',
);
}
return $form;
}