function notifications_tags_user_form in Notifications 6
Same name and namespace in other branches
- 5 notifications_tags/notifications_tags.module \notifications_tags_user_form()
- 6.2 notifications_tags/notifications_tags.module \notifications_tags_user_form()
- 6.3 notifications_tags/notifications_tags.module \notifications_tags_user_form()
Returns the taxonomy subscription form
1 string reference to 'notifications_tags_user_form'
- notifications_tags_user_page in notifications_tags/
notifications_tags.module - Returns a list of taxonomy subscriptions
File
- notifications_tags/
notifications_tags.module, line 158 - Subscriptions to taxonomy terms
Code
function notifications_tags_user_form($form_state, $account) {
// query string for category subscriptions
$vocabularies = notifications_tags_vocabularies();
// Get subscriptions indexed by tid
$subscriptions = array();
$existing = notifications_get_subscriptions(array(
'type' => 'taxonomy',
'uid' => $account->uid,
), array(
'tid' => NULL,
), TRUE);
foreach ($existing as $subs) {
$subscriptions[$subs->fields['tid']] = $subs;
}
// Complete defaults
$defaults = array(
'sid' => 0,
'send_interval' => notifications_user_setting('send_interval', $account),
'send_method' => notifications_user_setting('send_method', $account),
'type' => 'taxonomy',
'event_type' => 'node',
);
$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(),
);
//$subsrows['subform'][] = array('#value' => t('Current subscriptions:'));
$form['subscriptions'] = array(
'#tree' => TRUE,
);
// Hide send methods if only one
$send_methods = _notifications_send_methods();
$header = array(
theme('table_select_header_cell'),
t('Term'),
t('Send interval'),
);
if (count($send_methods) > 1) {
$header[] = t('Send method');
}
foreach ($vocabularies as $vid => $vocab) {
// display vocabulary name and group terms together
$form['subscriptions'][$vid] = array(
'#type' => 'fieldset',
'#title' => check_plain($vocab->name),
'#tree' => TRUE,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#theme' => 'notifications_form_table',
'#header' => $header,
'#parents' => array(
'subscriptions',
),
);
// @ TODO create mechanism to allow users to
// subscribe to all terms under this vocabulary
$tree = taxonomy_get_tree($vocab->vid);
$field = 'tid';
foreach ($tree as $term) {
$key = $term->tid;
$rowdefaults = isset($subscriptions[$key]) ? (array) $subscriptions[$key] : array();
$rowdefaults += $defaults;
$form['subscriptions'][$vid]['checkbox'][$key] = array(
'#type' => 'checkbox',
'#default_value' => $rowdefaults['sid'],
);
$form['subscriptions'][$vid]['title'][$key] = array(
'#value' => check_plain($term->name),
);
$form['subscriptions'][$vid]['send_interval'][$key] = array(
'#type' => 'select',
'#options' => _notifications_send_intervals(),
'#default_value' => $rowdefaults['send_interval'],
);
if (count($send_methods) > 1) {
$form['subscriptions'][$vid]['send_method'][$key] = array(
'#type' => 'select',
'#options' => _notifications_send_methods(),
'#default_value' => $rowdefaults['send_method'],
);
}
else {
$form['subscriptions'][$vid]['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'),
);
$form['#submit'][] = 'notifications_content_form_submit';
return $form;
}