Earlier today I was thinking about how you might have a filter you wanted added to a separately exported format, without wanting it to be a dependency. Example: You have an Input Format/Wysiwyg Feature, and you want to have an optional module that adds more stuff.

In it's role as an exportables facilitator for input formats, would an API function to easily enable an Input Filter for a given format make sense here? (Does not exist in Core.)

I have code mostly ready if this is the place for it.

Comments

dagmar’s picture

Status: Active » Postponed (maintainer needs more info)

I'm not sure to understand your point. This is what I can do: provide a hook to modify an input_format when it is loaded from code before caching.

Input formats cannot be disabled/enabled since there is a lot of code (from Drupal core) that doesn't contemplate that an input format can be disabled. If exists, it is available to be used.

Maybe if you provide a real use case for this feature we can see if this can be achieve or not.

Thanks

Grayside’s picture

Let me ask my question more clearly:

I have a WYSIWYG feature. It uses this module to create a new Input Format. We also have a feature based on the Inline module. I would like the input filter created by the Inline module to automatically be added to our WYSIWYG's input format.

Because the Input Filter feature comes along later, I cannot rely on the standard import of the WYSIWYG feature to carry it in. (And do not want to mandate a feature reversion to pull the input filter in via a features import pipe alter of some sort.)

Therefore, this requires a sort of API call that is not part of the core architecture of the Input Formats API or the core filter.module. I see this as a part of the core mission of Input Formats to expedite the creation of input format exportables and features.

Here is what I am thinking, for my specific use case:

/**
 * Modify the specified input format to activate the inline filter.
 */
function ucsb_inline_image_activate_filter($format_id = NULL) {
  if ($format_id == NULL) {
    $format_id = variable_get('filter_default_format', FILTER_FORMAT_DEFAULT);
  }
  $format = filter_format_load($format_id);

  if ($format === FALSE) {
    drupal_set_message('Inline could not be activated for an invalid input format.', 'warning');
    return FALSE;
  }
  
  $filters = filter_list_format($format_id);
  if (!array_key_exists('inline/0', $filters)) {
    db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, 'inline', 0, 10)", $format->format);
    drupal_set_message(t('Inline filter activated for the !format input format.', array('!format' => $format->name)));
    cache_clear_all($format->format .':', 'cache_filter', TRUE);
  }
  return TRUE;
}

This whole thing amounts to being able to turn on an Input Filter feature that enhances an Input Format feature.