function simplenews_node_tab_send_form_submit in Simplenews 7.2
Same name and namespace in other branches
- 6.2 simplenews.module \simplenews_node_tab_send_form_submit()
- 7 includes/simplenews.admin.inc \simplenews_node_tab_send_form_submit()
@todo
File
- includes/
simplenews.admin.inc, line 1971 - Newsletter admin, subscription admin, simplenews settings
Code
function simplenews_node_tab_send_form_submit($form, &$form_state) {
$values = $form_state['values'];
$node = node_load($values['nid']);
// Save the recipient handler and it's settings.
simplenews_issue_handler($node, $values['simplenews']['recipient_handler']);
if (!empty($form['simplenews']['recipient_handler_settings'])) {
ctools_include('plugins');
$handler = $values['simplenews']['recipient_handler'];
$handler = ctools_get_plugins('simplenews', 'recipient_handlers', $handler);
$class = $handler['class'];
if (method_exists($class, 'settingsFormSubmit')) {
$settings = $class::settingsFormSubmit($form['simplenews']['recipient_handler_settings'], $form_state);
simplenews_issue_handler_settings($node, $settings);
}
}
// Send newsletter to all subscribers or send test newsletter
module_load_include('inc', 'simplenews', 'includes/simplenews.mail');
if ($values['simplenews']['send'] == SIMPLENEWS_COMMAND_SEND_NOW) {
simplenews_add_node_to_spool($node);
// Attempt to send immediatly, if configured to do so.
if (simplenews_mail_attempt_immediate_send(array(
'entity_id' => $node->nid,
'entity_type' => 'node',
))) {
drupal_set_message(t('Newsletter %title sent.', array(
'%title' => $node->title,
)));
}
else {
drupal_set_message(t('Newsletter %title pending.', array(
'%title' => $node->title,
)));
}
}
elseif ($values['simplenews']['send'] == SIMPLENEWS_COMMAND_SEND_TEST) {
simplenews_send_test($node, $form_state['test_addresses']);
}
// If the selected command is send on publish, just set the newsletter status.
if ($values['simplenews']['send'] == SIMPLENEWS_COMMAND_SEND_PUBLISH) {
simplenews_issue_status($node, SIMPLENEWS_STATUS_SEND_PUBLISH);
drupal_set_message(t('The newsletter will be sent when the content is published.'));
}
node_save($node);
}