Same name and namespace in other branches
  1. 4.7.x modules/filter.module \filter_admin_format_form_submit()
  2. 6.x modules/filter/filter.admin.inc \filter_admin_format_form_submit()
  3. 7.x modules/filter/filter.admin.inc \filter_admin_format_form_submit()

Process filter format form submissions.

File

modules/filter/filter.module, line 483
Framework for handling filtering of content.

Code

function filter_admin_format_form_submit($form_id, $form_values) {
  $format = isset($form_values['format']) ? $form_values['format'] : NULL;
  $current = filter_list_format($format);
  $name = trim($form_values['name']);
  $cache = TRUE;

  // Add a new filter format.
  if (!$format) {
    $new = TRUE;
    db_query("INSERT INTO {filter_formats} (name) VALUES ('%s')", $name);
    $format = db_result(db_query("SELECT MAX(format) AS format FROM {filter_formats}"));
    drupal_set_message(t('Added input format %format.', array(
      '%format' => $name,
    )));
  }
  else {
    drupal_set_message(t('The input format settings have been updated.'));
  }
  db_query("DELETE FROM {filters} WHERE format = %d", $format);
  foreach ($form_values['filters'] as $id => $checked) {
    if ($checked) {
      list($module, $delta) = explode('/', $id);

      // Add new filters to the bottom.
      $weight = isset($current[$id]->weight) ? $current[$id]->weight : 10;
      db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", $format, $module, $delta, $weight);

      // Check if there are any 'no cache' filters.
      $cache &= !module_invoke($module, 'filter', 'no cache', $delta);
    }
  }

  // We store the roles as a string for ease of use.
  // We should always set all roles to TRUE when saving a default role.
  // We use leading and trailing comma's to allow easy substring matching.
  $roles = array();
  if (isset($form_values['roles'])) {
    foreach ($form_values['roles'] as $id => $checked) {
      if ($checked) {
        $roles[] = $id;
      }
    }
  }
  $roles = ',' . implode(',', $form_values['default_format'] ? array_keys(user_roles()) : $roles) . ',';
  db_query("UPDATE {filter_formats} SET cache = %d, name='%s', roles = '%s' WHERE format = %d", $cache, $name, $roles, $format);
  cache_clear_all($format . ':', 'cache_filter', TRUE);

  // If a new filter was added, return to the main list of filters. Otherwise, stay on edit filter page to show new changes.
  if ($new) {
    return 'admin/settings/filters/';
  }
  else {
    return 'admin/settings/filters/' . $format;
  }
}