function subscriptions_ui_node_form in Subscriptions 2.0.x
Same name and namespace in other branches
- 5.2 subscriptions_ui.module \subscriptions_ui_node_form()
- 6 subscriptions_ui.module \subscriptions_ui_node_form()
- 7 subscriptions_ui.module \subscriptions_ui_node_form()
Returns the form definition for the node subform.
_state
Parameters
$form:
$node: Must be a valid node object.
$expand: Force the fieldset to expand if TRUE.
Return value
array|null
2 string references to 'subscriptions_ui_node_form'
- old_subscriptions_ui_node_view in subscriptions_ui/
subscriptions_ui.module - Implements hook_node_view().
- subscriptions_ui_block_view in subscriptions_ui/
subscriptions_ui.module - Implements hook_block_view().
File
- subscriptions_ui/
subscriptions_ui.module, line 177 - Provides a user interface for Subscriptions.
Code
function subscriptions_ui_node_form($form, &$form_state, $node, $expand = NULL) {
global $user;
$account = $user;
$expand = $expand === TRUE || variable_get('subscriptions_form_expanded', 0);
if (subscriptions_node_is_blocked($node->nid)) {
return NULL;
}
/** @var $blocked_types array */
$blocked_types = variable_get('subscriptions_blocked_content_types', []);
if (in_array($node->type, $blocked_types)) {
if (!user_access('subscribe to all content types', $account)) {
return NULL;
}
$is_blocked = TRUE;
}
$show_node_info = variable_get('node_submitted_' . $node->type, 1);
$node_options = module_invoke_all('subscriptions', 'node_options', $account, $node);
// Allow other modules to alter the node options.
drupal_alter('subscriptions_node_options', $node_options);
if (!$node_options || !user_access('subscribe to content', $account)) {
return [];
}
uasort($node_options, '_subscriptions_cmp_by_weight');
foreach ([
db_query("SELECT sid, module, field, value, author_uid, send_interval, send_updates, send_comments FROM {subscriptions} WHERE module = :module AND field = :field AND value = :value AND recipient_uid = :recipient_uid", [
':module' => 'node',
':field' => 'nid',
':value' => $node->nid,
':recipient_uid' => $account->uid,
], [
'fetch' => PDO::FETCH_ASSOC,
]),
db_query("SELECT sid, module, field, value, author_uid, send_interval, send_updates, send_comments FROM {subscriptions} WHERE module = :module AND field <> :field AND recipient_uid = :recipient_uid", [
':module' => 'node',
':field' => 'nid',
':recipient_uid' => $account->uid,
], [
'fetch' => PDO::FETCH_ASSOC,
]),
] as $result) {
foreach ($result as $s) {
$subscriptions[$s['field']][$s['value']][$s['author_uid']] = $s;
}
}
// Process all options building the array of indexed params for each
$nonlabeled_options = $options = $params = $default_comments = $default_updates = $default_subscriptions = [];
$index = 1;
// If we start with zero, get some value sent as 0 => 0
$default_send_intervals = [];
foreach ($node_options as $field => $field_options) {
foreach ($field_options as $option) {
if (!is_array($option) || isset($option['#access']) && !$option['#access']) {
continue;
}
if ((!$show_node_info || !variable_get('subscriptions_show_by_author_options', 1)) && isset($option['params']['author_uid']) && $option['params']['author_uid'] >= 0) {
continue;
}
if ($option['params']['module'] == 'node' && $option['params']['field'] == 'type' && !empty($is_blocked)) {
$option['name'] .= ' ' . SUBSCRIPTIONS_UNAVAILABLE;
}
//$options[$index] = (isset($option['link']) ? l($option['name'], 'subscriptions/add/' . $option['link'], array('query' => drupal_get_destination(), 'html' => TRUE)) : $option['name']);
$options[$index] = $option['name'];
$nonlabeled_options[$index] = '';
$params[$index] = $param = $option['params'] + [
'author_uid' => -1,
];
if (isset($subscriptions[$param['field']][$param['value']][$param['author_uid']])) {
$default_subscriptions[] = $index;
$default_send_intervals[$index] = $subscriptions[$param['field']][$param['value']][$param['author_uid']]['send_interval'];
if ($subscriptions[$param['field']][$param['value']][$param['author_uid']]['send_comments']) {
$default_comments[] = $index;
}
if ($subscriptions[$param['field']][$param['value']][$param['author_uid']]['send_updates']) {
$default_updates[] = $index;
}
}
else {
$default_send_intervals[$index] = _subscriptions_get_setting('send_interval', $account);
if (_subscriptions_get_setting('send_comments', $account)) {
$default_comments[] = $index;
}
if (_subscriptions_get_setting('send_updates', $account)) {
$default_updates[] = $index;
}
}
$index++;
}
}
$form['params'] = [
'#type' => 'value',
'#value' => $params,
];
$form['wrapper'] = [
'#type' => 'fieldset',
'#title' => filter_xss(t('Subscribe') . (!empty($is_blocked) ? ' ' . SUBSCRIPTIONS_UNAVAILABLE : ''), [
'span',
]),
'#collapsible' => TRUE,
'#collapsed' => !$expand,
'#theme' => 'subscriptions_ui_table',
'#attributes' => [
'id' => 'subscribe',
],
];
$form['wrapper']['subscriptions'] = [
'#type' => 'checkboxes',
'#default_value' => $default_subscriptions,
'#options' => $options,
'#access' => TRUE,
];
$form['wrapper']['updates'] = [
'#type' => 'checkboxes',
'#default_value' => $default_updates,
'#options' => $nonlabeled_options,
'#access' => _subscriptions_get_setting('send_updates_visible', $user) > 0,
];
if (module_exists('comment') && user_access('access comments')) {
$form['wrapper']['comments'] = [
'#type' => 'checkboxes',
'#default_value' => $default_comments,
'#options' => $nonlabeled_options,
'#access' => _subscriptions_get_setting('send_comments_visible', $user) > 0,
];
}
$form['wrapper']['footer'] = [
'#type' => 'item',
'#description' => t('The master checkboxes in the left-most column turn the given subscription on or off. Depending on the setup of the site, you may have additional options for active subscriptions.'),
'#weight' => 9,
];
$form['wrapper']['submit'] = [
'#type' => 'submit',
'#value' => t('Save'),
'#weight' => 10,
];
$form['account'] = [
'#type' => 'value',
'#value' => $account,
];
$form['send_intervals'] = [
'#type' => 'value',
'#value' => $default_send_intervals,
];
return $form;
}