You are here

function mostpopular_intervals_admin_form_submit in Drupal Most Popular 7

1 string reference to 'mostpopular_intervals_admin_form_submit'
mostpopular_intervals_admin_form in ./mostpopular.intervals.inc

File

./mostpopular.intervals.inc, line 191
Provides an admin GUI for configuring intervals.

Code

function mostpopular_intervals_admin_form_submit($form, $form_state) {
  $exist = array();
  foreach ($form_state['intervals'] as $bid => $block) {
    foreach ($block as $iid => $interval) {

      // Save the interval
      $status = FALSE;
      if (empty($interval->iid)) {
        $status = 'added';
      }
      if (!empty($interval->dirty)) {
        $status = 'updated';
      }
      mostpopular_interval_save($interval);

      // Rehash the interval by its new ID.
      $exist[$bid][$interval->iid] = $interval;
      if ($status) {
        drupal_set_message(t('Interval %title was @status.', array(
          '%title' => mostpopular_interval_title($interval),
          '@status' => $status,
        )));
      }
    }
  }

  // Identify the intervals to remove
  $intervals = mostpopular_intervals();
  foreach ($intervals as $interval) {
    if (!isset($exist[$interval->bid][$interval->iid])) {

      // Remove the interval and any cached items
      mostpopular_interval_delete($interval);
      drupal_set_message(t('Interval %title was removed.', array(
        '%title' => mostpopular_interval_title($interval),
      )));
    }
  }
  $form_state['intervals'] = $exist;
  drupal_set_message(t('The interval configuration has been saved.'));
}