function simplenews_scheduler_submit in Simplenews Scheduler 8
Same name and namespace in other branches
- 6.2 simplenews_scheduler.module \simplenews_scheduler_submit()
- 7 simplenews_scheduler.module \simplenews_scheduler_submit()
- 2.0.x simplenews_scheduler.module \simplenews_scheduler_submit()
Additional submit handler for the node_tab_send_form of simplenews.
1 string reference to 'simplenews_scheduler_submit'
File
- ./
simplenews_scheduler.module, line 220 - Simplenews Scheduler module allows a schedule to be set for sending (and resending) a Simplenews item.
Code
function simplenews_scheduler_submit(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$node = $form_state
->get('node');
$nid = $node
->id();
if ($form_state
->getValue('enable_scheduler')) {
$stoptype = $values['stoptype'];
$start_date = strtotime($values['start_date']);
$stop_date = $stoptype == 1 ? strtotime($values['stop_date']) : 0;
$record = array(
'nid' => $nid,
'send_interval' => $values['interval'],
'interval_frequency' => $values['frequency'],
'start_date' => $start_date,
'stop_type' => $stoptype,
'stop_date' => $stop_date,
'stop_edition' => $values['stop_edition'],
'title' => $values['title'],
'activated' => 1,
);
// For a new scheduler, add the next_run time.
if (!isset($values['next_run'])) {
$record['next_run'] = $start_date;
}
// Update scheduler record.
db_merge('simplenews_scheduler')
->key(array(
'nid' => $nid,
))
->fields($record)
->execute();
}
else {
// The form was submitted with the checkbox unchecked, disable an eventually
// existing scheduler configuration.
db_update('simplenews_scheduler')
->condition('nid', $nid)
->fields([
'activated' => 0,
])
->execute();
}
\Drupal::entityManager()
->getStorage('node')
->resetCache([
$node
->id(),
]);
drupal_set_message(t('Newsletter schedule preferences have been saved.'));
}