function subscriptions_content_form_alter in Subscriptions 5.2
Same name and namespace in other branches
- 6 subscriptions_content.module \subscriptions_content_form_alter()
- 7 subscriptions_content.module \subscriptions_content_form_alter()
- 2.0.x subscriptions_content/subscriptions_content.module \subscriptions_content_form_alter()
Implementation of hook_form_alter()
Add
- the Content Settings part to admin/settings/subscriptions,
- additional fields to the node and digest Mail Editor forms, and
- the Send Subscriptions Notifications checkbox to the Publishing Options fieldset on the node edit form.
File
- ./
subscriptions_content.module, line 305 - Subscriptions to content events
Code
function subscriptions_content_form_alter($form_id, &$form) {
global $user;
$tr = 't';
if ($form_id == 'subscriptions_settings_form') {
// General content settings
$select = array();
$select[0] = '<' . t('none') . '>';
$nodetypes = node_get_types();
foreach ($nodetypes as $ntype => $nname) {
$select[$ntype] = $nname->name;
}
$form['content'] = array(
'#type' => 'fieldset',
'#title' => t('Content settings'),
'#collapsible' => TRUE,
'#weight' => -10,
);
$form['content']['subscriptions_unlisted_content_types'] = array(
'#type' => 'select',
'#title' => t('Unlisted content types'),
'#default_value' => variable_get('subscriptions_unlisted_content_types', array()),
'#options' => $select,
'#description' => t('Select content types which should be <strong>removed from subscription listings</strong>.<br />The content may still be available for subscribing via different kinds of subscriptions, but subscribing by content type will be unavailable for the selected types.'),
'#multiple' => TRUE,
);
$form['content']['subscriptions_blocked_content_types'] = array(
'#type' => 'select',
'#title' => t('Blocked content types'),
'#default_value' => variable_get('subscriptions_blocked_content_types', array()),
'#options' => $select,
'#description' => t('Select content types which should be <strong>completely unavailable for subscribing</strong>, i.e. content of the selected types will never trigger notifications for regular users.'),
'#multiple' => TRUE,
);
$form['content']['subscriptions_blocked_content_types_note'] = array(
'#type' => 'item',
'#title' => t('Note'),
'#value' => t("The %permission permission grants normal access to unlisted and blocked content types; this is intended as an administrative function, and the content types and links will be marked with a '!symbol' symbol (and appear !red_ON like this !red_OFF in the case of blocked types).", array(
'%permission' => t('subscribe to all content types'),
'!symbol' => SUBSCRIPTIONS_UNAVAILABLE,
'!red_ON' => '<span class="error">',
'!red_OFF' => '</span>',
)),
);
$form['content']['subscriptions_blocked_nodes'] = array(
'#type' => 'textfield',
'#title' => t('Blocked nodes'),
'#size' => 100,
'#maxlength' => 1000,
'#default_value' => variable_get('subscriptions_blocked_nodes', ''),
'#description' => t('Enter the IDs of nodes that should be <strong>completely unavailable for subscribing</strong>, separated by spaces.'),
);
$form['#validate']['_subscriptions_content_validate_blocked_nodes'] = array();
$statics = variable_get('subscriptions_static_content_types', array());
$avoid_empty_subscribe_links = variable_get('subscriptions_avoid_empty_subscribe_links', 0);
$form['content']['static_content'] = array(
'#type' => 'fieldset',
'#title' => t('Static content'),
'#collapsible' => TRUE,
'#collapsed' => (empty($statics) || count($statics) == 1 && isset($statics[0])) && !$avoid_empty_subscribe_links,
);
$form['content']['static_content']['subscriptions_static_content_types'] = array(
'#type' => 'select',
'#title' => t('Static content types'),
'#default_value' => $statics,
'#options' => $select,
'#description' => t('Select content types which do not change nor receive comments and thus should not have the %option option.', array(
'%option' => t('Subscribe to this page'),
)),
'#multiple' => TRUE,
);
$form['content']['static_content']['subscriptions_avoid_empty_subscribe_links'] = array(
'#type' => 'checkbox',
'#title' => t('Avoid empty %Subscribe links', array(
'%Subscribe' => t('Subscribe'),
)),
'#default_value' => $avoid_empty_subscribe_links,
'#description' => t('Nodes of %Static_content_types may end up with no %Subscribe options at all. Turn this option on to avoid displaying %Subscribe links in this case. The default is OFF, because this option causes processing overhead for each node view operation.', array(
'%Static_content_types' => t('Static content types'),
'%Subscribe' => t('Subscribe'),
)),
);
$form['content']['subscriptions_generate_full_node'] = array(
'#type' => 'checkbox',
'#title' => t('Generate the %full_node variable', array(
'%full_node' => '!full_node',
)),
'#default_value' => variable_get('subscriptions_generate_full_node', 0),
'#description' => t("Generating this variable causes considerable overhead even if it's not used, and <strong>it may even cause errors</strong>, depending on the !content_type! Default is OFF.", array(
'!content_type' => $tr('content type'),
)),
);
}
if ($form_id == 'mail_edit_form' && substr($form['mailkey']['#value'], 0, 13) == 'subscriptions') {
include_once drupal_get_path('module', 'subscriptions_mail') . '/subscriptions_mail.templates.inc';
$mailkey = $form['mailkey']['#value'];
$mkey = substr($mailkey, 13);
$form['subscriptions']['#tree'] = TRUE;
$help_key = 'help';
$form[$help_key]['#variables'] += array(
'!site' => t('The name of the site.'),
'!manage_url' => t('The URL where the user can manage her subscriptions.'),
);
if ($mailkey == SUBSCRIPTIONS_DIGEST_MAILKEY) {
$form[$help_key]['#variables'] += array(
'!bodies' => t('The digested items (separated by a separator), as defined below:'),
);
$form['subject']['#title'] = 'Digest subject';
$form['body']['#title'] = 'Digest body';
$form['digest_item']['#default_value'] = db_result(db_query("SELECT item_body FROM {subscriptions_mail_edit} WHERE mailkey = '%s'", SUBSCRIPTIONS_DIGEST_MAILKEY . '-item'));
$form['digest_item_comment']['#default_value'] = db_result(db_query("SELECT item_body FROM {subscriptions_mail_edit} WHERE mailkey = '%s'", SUBSCRIPTIONS_DIGEST_MAILKEY . '-item-comment'));
foreach (array(
'subject' => subscriptions_mail_template('DSUBJ'),
'body' => subscriptions_mail_template('DBODY'),
'digest_item' => subscriptions_mail_template('DITEM'),
'digest_item_comment' => subscriptions_mail_template('DITEMCMT'),
) as $key => $value) {
if (empty($form[$key]['#default_value'])) {
$form[$key]['#default_value'] = $value;
}
}
foreach (array(
'!sender_name',
'!sender_page',
'!sender_contact_page',
'!sender_has_contact_page',
) as $key) {
unset($form['help']['#variables'][$key]);
}
$form['digest_item'] += array(
'#type' => 'textarea',
'#title' => t('Digest item body'),
'#description' => t('The body of each item in the digest.'),
'#weight' => 33,
'#rows' => 5,
);
$form['item_help'] = array(
'#variables' => array(),
'#theme' => 'mail_edit_variables',
'#weight' => 35,
);
$help_key = 'item_help';
}
$form[$help_key]['#variables'] += array(
'!subs_type' => t("The type of the subscription, like '!thread' or '!category'.", array(
'!thread' => t('thread'),
'!category' => $tr('category'),
)),
'!node_type' => t("The type of the node, like '!forum' or '!story'.", array(
'!forum' => 'forum',
'!story' => 'story',
)),
'!title' => t('The title of the subscriptions item.'),
'!teaser' => t('An excerpt of the subscriptions item.'),
'!body' => t('The body of the subscriptions item.'),
'!full_node' => t('The full node as it appears on the website (requires the %HTML_to_text module to be installed, and must be specifically enabled !here).', array(
'%HTML_to_text' => $tr('HTML to text'),
'!here' => l(t('here'), 'admin/settings/subscriptions', array(), NULL, 'edit-subscriptions-generate-full-node'),
)),
'!url' => t('The URL of the item.'),
'!unsubscribe_url' => t('The user can unsubscribe by clicking this link.'),
);
if (isset($form['addon_help'])) {
$form[$help_key]['#variables'] += $form['addon_help']['#variables'];
unset($form['addon_help']);
}
if ($mailkey == SUBSCRIPTIONS_DIGEST_MAILKEY) {
$form[$help_key]['#variables'] += array(
'!has_new_comments' => t('The comments state: 1 = comments are available in !comments, 0 = no comments.'),
'!comments' => t('One or more comments if available, otherwise empty.<br />The rendering of the comments is defined by the following template:'),
);
$comment = db_result(db_query("SELECT item_body FROM {subscriptions_mail_edit} WHERE mailkey = '%s'", SUBSCRIPTIONS_DIGEST_MAILKEY . '-comment'));
$comment = $comment ? $comment : subscriptions_mail_template('DITEMCMT');
$form['digest_item_comment'] += array(
'#type' => 'textarea',
'#title' => t('Digest item comment'),
'#default_value' => $comment,
'#description' => t('The comments inside a digest item body.'),
'#weight' => 36,
'#rows' => 2,
);
$form['comment_help'] = array(
'#weight' => 37,
);
$separator = db_result(db_query("SELECT item_body FROM {subscriptions_mail_edit} WHERE mailkey = '%s'", SUBSCRIPTIONS_DIGEST_MAILKEY . '-separator'));
$separator = $separator ? $separator : subscriptions_mail_template('SEP');
$form['digest_separator'] = array(
'#type' => 'textarea',
'#title' => t('Digest item separator'),
'#default_value' => $separator,
'#description' => t('The separator between digest items (if needed).'),
'#weight' => 38,
'#rows' => 2,
);
$form['#submit']['subscriptions_content_mail_edit_submit'] = array();
}
else {
// ! $mailkey == SUBSCRIPTIONS_DIGEST_MAILKEY
switch ($mkey) {
case '-node-type-forum':
$form['help']['#variables'] += array(
'!term_name' => t('The name of the forum.'),
);
break;
case '-node-tid':
$form['help']['#variables'] += array(
'!term_name' => t('The name of the term.'),
);
break;
}
$tr = 't';
$form['help']['#variables'] += array(
'!is_new' => t('The type of notification: 1 = new item, 0 = otherwise.'),
'!is_updated' => t('The type of notification: 1 = updated (possibly new and already updated) item, 0 = otherwise.'),
'!is_old' => t('The type of notification: 1 = neither new nor updated item, 0 = otherwise.'),
'!is_published' => t('The publication state: 1 = published, 0 = unpublished.<br />(Unpublished nodes are sent to users with the %administer_nodes permission only.)', array(
'%administer_nodes' => $tr('administer nodes'),
)),
'!files' => t('The list of attached files, one per line, if any, otherwise empty.'),
'!has_new_comments' => t('The comments state: 1 = comments are available in !comments, 0 = no comments.'),
);
if ($mkey == '-node-nid') {
$comment_body = db_result(db_query("SELECT item_body FROM {subscriptions_mail_edit} WHERE mailkey = '%s'", SUBSCRIPTIONS_COMMENT_MAILKEY . '-item'));
$comment_body = $comment_body ? $comment_body : subscriptions_mail_template('CITEM');
$form['comment_body'] = array(
'#type' => 'textarea',
'#title' => t('Comment body'),
'#default_value' => $comment_body,
'#description' => t('The body of each comment.'),
'#weight' => 33,
'#rows' => 3,
);
$form['comment_help'] = array(
'#weight' => 35,
);
$separator = db_result(db_query("SELECT item_body FROM {subscriptions_mail_edit} WHERE mailkey = '%s'", SUBSCRIPTIONS_COMMENT_MAILKEY . '-separator'));
$separator = $separator ? $separator : subscriptions_mail_template('SEP');
$form['comment_separator'] = array(
'#type' => 'textarea',
'#title' => t('Comment separator'),
'#default_value' => $separator,
'#description' => t('The separator between comments (if needed).'),
'#weight' => 37,
'#rows' => 2,
);
$form['help']['#variables'] += array(
'!comments' => t('One or more comments if available, otherwise empty.<br />The rendering of the comments is defined by the following templates:'),
);
}
else {
$form['help']['#variables'] += array(
'!comments' => t('One or more comments if available, otherwise empty.<br />The rendering of the comments is defined by the <a href="subscriptions-node-nid#edit-comment-body">comment templates</a>.'),
);
}
if (empty($form['subject']['#default_value'])) {
$form['subject']['#default_value'] = subscriptions_mail_template('SUBJ');
}
if (empty($form['body']['#default_value'])) {
$form['body']['#default_value'] = subscriptions_mail_template('BODY');
}
$form['#submit']['subscriptions_content_mail_edit_submit'] = array();
}
if (isset($form['comment_help']['#weight'])) {
$tr = 't';
$form['comment_help'] += array(
'#theme' => 'mail_edit_variables',
'#variables' => array(
'!comment_name' => t('The name of the comment author.'),
'!comment_title' => t('The title of the comment.'),
'!comment_text' => t('The body text of the comment.'),
'!comment_url' => t('The direct URL of the comment.'),
'!comment_is_new' => t('The type of comment notification: 1 = new comment, 0 = updated comment.'),
'!comment_is_published' => t('The comment publication state: 1 = published, 0 = unpublished.<br />(Unpublished comments are sent to users with the %administer_comments permission only.)', array(
'%administer_comments' => $tr('administer comments'),
)),
),
);
}
}
if (isset($form['type']) && $form['type']['#value'] . '_node_form' == $form_id) {
if (isset($form['options'])) {
$tr = 't';
$form['options']['subscriptions_notify'] = array(
'#type' => 'checkbox',
'#title' => t('Send subscriptions notifications'),
'#description' => t('You may want to turn this OFF when you only change %Promoted_to_front_page or %Sticky_at_top_of_lists, otherwise Subscriptions will send out "update" notifications; this option is not saved.<br />Subscriptions does not send notifications for unpublished nodes (except to users who have the %administer_nodes permission), but when you set %Published to ON, Subscriptions will send out "new" notifications, unless you turn this off here.', array(
'%Promoted_to_front_page' => $tr('Promoted to front page'),
'%Sticky_at_top_of_lists' => $tr('Sticky at top of lists'),
'%administer_nodes' => $tr('administer nodes'),
'%Published' => $tr('Published'),
)),
'#weight' => 5,
'#default_value' => isset($form['#node']->subscriptions_notify) ? $form['#node']->subscriptions_notify : TRUE,
);
}
}
if ($form_id == 'node_admin_nodes') {
$handlers = array_reverse($form['#submit']);
$handlers['subscriptions_content_node_admin_nodes_submit'] = array();
$form['#submit'] = array_reverse($handlers);
// run before node_admin_nodes_submit()!
}
if ($form_id == 'comment_form' && isset($form['subscriptions_notify'])) {
// create the Administration fieldset if it doesn't exist:
if (!isset($form['admin'])) {
$tr = 't';
$form['admin'] = array(
'#type' => 'fieldset',
'#title' => $tr('Administration'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => -2,
);
}
// move the checkbox inside the Administration fieldset:
$form['admin']['subscriptions_notify'] = $form['subscriptions_notify'];
unset($form['subscriptions_notify']);
}
}