function simplenews_node_tab_send_form in Simplenews 7.2
Same name and namespace in other branches
- 6.2 simplenews.module \simplenews_node_tab_send_form()
- 7 includes/simplenews.admin.inc \simplenews_node_tab_send_form()
@todo
1 string reference to 'simplenews_node_tab_send_form'
- simplenews_node_tab_page in includes/
simplenews.admin.inc - Menu callback; Newsletter tab page.
File
- includes/
simplenews.admin.inc, line 1784 - Newsletter admin, subscription admin, simplenews settings
Code
function simplenews_node_tab_send_form($form, &$form_state, $node) {
$status = simplenews_issue_status($node);
$form = array();
// We will need the node
$form['nid'] = array(
'#type' => 'value',
'#value' => $node->nid,
);
// @todo delete this fieldset?
$form['simplenews'] = array(
'#type' => 'fieldset',
'#title' => t('Send newsletter'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#tree' => TRUE,
);
// Translations of newsletters don't have the 'send' option. Only the
// translation source (and non translated) newsletters will get these options.
if (module_exists('translation') && translation_supported_type($node->type) && (isset($node->translate) && $node->tnid > 0 && $node->tnid != $node->nid)) {
$form['simplenews']['#description'] = t('This newsletter issue is part of a translation set. Sending this set is controlled from the <a href="@link">translation source newsletter</a>.', array(
'@link' => url('node/' . $node->tnid),
));
// @todo Translated nodes must also have the same newsletter!
// Move the newsletter in here and give the user feedback.
}
else {
// Show newsletter sending options if newsletter has not been send yet.
// If send a notification is shown.
if ($status == SIMPLENEWS_STATUS_SEND_NOT || $status == SIMPLENEWS_STATUS_SEND_PUBLISH) {
$options = array(
SIMPLENEWS_COMMAND_SEND_TEST => t('Send one test newsletter to the test address'),
);
// Add option to send on publish when the node is unpublished.
if ($node->status == NODE_NOT_PUBLISHED) {
$options[SIMPLENEWS_COMMAND_SEND_PUBLISH] = t('Send newsletter when published');
}
else {
$options[SIMPLENEWS_COMMAND_SEND_NOW] = t('Send newsletter');
}
if ($status == SIMPLENEWS_STATUS_SEND_PUBLISH) {
$send_default = SIMPLENEWS_STATUS_SEND_PUBLISH;
}
else {
$send_default = variable_get('simplenews_send', SIMPLENEWS_COMMAND_SEND_TEST);
}
$form['simplenews']['send'] = array(
'#type' => 'radios',
'#title' => t('Send newsletter'),
'#default_value' => $send_default,
'#options' => $options,
'#attributes' => array(
'class' => array(
'simplenews-command-send',
),
),
);
$address_default = variable_get('site_mail', ini_get('sendmail_from'));
if (variable_get('simplenews_test_address_override', 0)) {
$form['simplenews']['test_address'] = array(
'#type' => 'textfield',
'#title' => t('Test email addresses'),
'#description' => t('A comma-separated list of email addresses to be used as test addresses.'),
'#default_value' => variable_get('simplenews_test_address', $address_default),
'#size' => 60,
'#maxlength' => 128,
);
}
else {
$form['simplenews']['test_address'] = array(
'#type' => 'value',
'#value' => variable_get('simplenews_test_address', $address_default),
);
}
$default_handler = isset($form_state['values']['simplenews']['recipient_handler']) ? $form_state['values']['simplenews']['recipient_handler'] : simplenews_issue_handler($node);
$options = simplenews_handler_field_allowed_values();
$form['simplenews']['recipient_handler'] = array(
'#type' => 'select',
'#title' => t('Recipients'),
'#description' => t('Please select to configure who to send the email to.'),
'#options' => $options,
'#default_value' => $default_handler,
'#access' => count($options) > 1,
'#ajax' => array(
'callback' => 'simplenews_node_tab_send_form_handler_update',
'wrapper' => 'recipient-handler-settings',
'method' => 'replace',
'effect' => 'fade',
),
);
// Get the handler class
ctools_include('plugins');
$handler = ctools_get_plugins('simplenews', 'recipient_handlers', $default_handler);
$class = $handler['class'];
$settings = simplenews_issue_handler_settings($node);
if (method_exists($class, 'settingsForm')) {
$element = array(
'#parents' => array(
'simplenews',
'recipient_handler_settings',
),
'#prefix' => '<div id="recipient-handler-settings">',
'#suffix' => '</div>',
);
$form['simplenews']['recipient_handler_settings'] = $class::settingsForm($element, $settings);
}
else {
$form['simplenews']['recipient_handler']['#suffix'] = '<div id="recipient-handler-settings"></div>';
}
}
else {
$form['simplenews']['none'] = array(
'#type' => 'checkbox',
'#return_value' => 0,
'#attributes' => array(
'checked' => 'checked',
'disabled' => 'disabled',
),
);
$form['simplenews']['none']['#title'] = $status == SIMPLENEWS_STATUS_SEND_READY ? t('This newsletter has been sent') : t('This newsletter is pending');
return $form;
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
}
return $form;
}