1 filter.module filter_format_save($format)

Saves a text format object to configuration.

Parameters

$format: A format object having the properties:

  • format: A machine-readable name representing the ID of the text format to save. If this corresponds to an existing text format, that format will be updated; otherwise, a new format will be created.
  • name: The title of the text format.
  • status: (optional) An integer indicating whether the text format is enabled (1) or not (0). Defaults to 1.
  • weight: (optional) The weight of the text format, which controls its placement in text format lists. If omitted, the weight is set to 0.
  • editor: (optional) The machine-readable name of the editor to use for this text format (e.g. 'ckeditor'). Defaults to NULL.
  • editor_settings: (optional) An associative array of settings for the specified editor. See standard_install() for an example.
  • filters: (optional) An associative, multi-dimensional array of filters assigned to the text format, keyed by the name of each filter and using the properties:

    • weight: (optional) The weight of the filter in the text format. If omitted, either the currently stored weight is retained (if there is one), or the filter is assigned a weight of 10, which will usually put it at the bottom of the list.
    • status: (optional) A boolean indicating whether the filter is enabled in the text format. If omitted, the filter will be disabled.
    • settings: (optional) An array of configured settings for the filter. See hook_filter_info() for details.

Return value

SAVED_NEW or SAVED_UPDATED.:

File

core/modules/filter/filter.module, line 369
Framework for handling the filtering of content.

Code

function filter_format_save($format) {
  $format = filter_format_build_format($format);

  // Save the filter format.
  $config = config('filter.format.' . $format->format);
  $is_new = $config->isNew();

  // Convert the object to arrays for saving.
  $format_data = (array) $format;
  foreach ($format_data['filters'] as $filter_name => $filter) {
    $filter_data = (array) $filter;
    if (isset($filter_data['name'])) {
      unset($filter_data['name']);
    }
    $format_data['filters'][$filter_name] = $filter_data;
  }
  if (isset($format_data['is_new'])) {
    unset($format_data['is_new']);
  }

  $config->setData($format_data);
  $config->save();

  if ($is_new) {
    module_invoke_all('filter_format_insert', $format);
    $return = SAVED_NEW;
  }
  else {
    module_invoke_all('filter_format_update', $format);
    // Explicitly indicate that the format was updated. We need to do this
    // since if the filters were updated but the format object itself was not,
    // the merge query above would not return an indication that anything had
    // changed.
    $return = SAVED_UPDATED;

    // Clear the filter cache whenever a text format is updated.
    cache('filter')->deletePrefix($format->format . ':');
  }

  filter_formats_reset();

  return $return;
}