You are here

function superfish_admin_settings_submit in Superfish 7

Custom submission handler for the settings form.

1 string reference to 'superfish_admin_settings_submit'
superfish_system_settings_form in ./superfish.admin.inc
Overriding system settings form.

File

./superfish.admin.inc, line 66
Functions that are only called on the admin pages.

Code

function superfish_admin_settings_submit($form, &$form_state) {
  $values =& $form_state['values'];
  $before = variable_get('superfish_number', 4);
  $after = $values['superfish_number'];

  // If the number of blocks has been decreased.
  if ($before > $after) {

    // How many blocks should be removed?
    $reduce = $before - $after;

    // Remove each block with all its variables.
    $delta = $after;
    for ($i = 0; $i < $reduce; $i++) {
      $delta++;
      db_delete('variable')
        ->condition('name', 'superfish_%%_' . $delta, 'LIKE')
        ->execute();
      db_delete('block')
        ->condition('module', 'superfish')
        ->condition('delta', $delta)
        ->execute();
      db_delete('block_role')
        ->condition('module', 'superfish')
        ->condition('delta', $delta)
        ->execute();
    }
    drupal_set_message(t('Successfully removed @number Superfish block(s).', array(
      '@number' => $reduce,
    )));
  }
}