function simplenews_node_tab_send_form in Simplenews 7
Same name and namespace in other branches
- 6.2 simplenews.module \simplenews_node_tab_send_form()
- 7.2 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 1839 - Newsletter admin, subscription admin, simplenews settings
Code
function simplenews_node_tab_send_form($form, &$form_state, $node) {
// First check if there already is a loaded simplenews object.
if (!empty($node->simplenews)) {
$simplenews_values = $node->simplenews;
}
elseif ($loaded = simplenews_newsletter_load($node->nid)) {
$simplenews_values = $loaded;
}
else {
$simplenews_values = (object) _simplenews_get_node_form_defaults($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 Category!
// Move the category 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 ($simplenews_values->status == SIMPLENEWS_STATUS_SEND_NOT || $simplenews_values->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 ($simplenews_values->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' => isset($simplenews_values->send) ? $simplenews_values->send : $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),
);
}
}
else {
$form['simplenews']['none'] = array(
'#type' => 'checkbox',
'#return_value' => 0,
'#attributes' => array(
'checked' => 'checked',
'disabled' => 'disabled',
),
);
$form['simplenews']['none']['#title'] = $simplenews_values->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;
}