You are here

function freelinking_get_plugins in Freelinking 6.3

Same name and namespace in other branches
  1. 7.3 freelinking.utilities.inc \freelinking_get_plugins()

Invoke hook_freelinking() to validate & sort available FL plugins.

This function is necessary to build any sort of interface involving plugin configuration. It is not the function to use in the creation of new plugins or overriding existing plugins. For that you want hook_freelinking().

Internal Note: Currently the plugins are generated for each plugin on the idea that different formats might have a number of configuration overrides. If this turns out to not be the case a single cached version of the plugins might be better.

Parameters

$format: The Text Format ID of the currently processed piece of text. Allows format-specific plugin overrides such as disabling certain plugins in a given format. The default 'all' refers to the plugins as provided by hook_freelinking().

$reset: (Default: FALSE) Reset the static cache.

Return value

An array of all plugins. Each plugin is itself an array.

See also

PLUGINS.txt

4 calls to freelinking_get_plugins()
freelinking_filter in ./freelinking.module
Implementation of hook_filter().
freelinking_filter_tips in ./freelinking.module
Implementation of hook_filter_tips().
freelinking_get_freelink in ./freelinking.utilities.inc
Process the target text into a link with the specified plugin.
freelinking_settings in ./freelinking.forms.inc
Build admin/settings page.

File

./freelinking.utilities.inc, line 81
Freelinking 3 Utilities

Code

function freelinking_get_plugins($format = 'all', $reset = FALSE) {
  static $plugins;
  if (empty($plugins[$format]) || $reset) {
    $freelinking = module_invoke_all('freelinking');

    // Validate & standardize plugins.
    foreach ($freelinking as $name => &$plugin) {

      // Confirm correct structure in plugin
      if (!isset($plugin['indicator']) || !isset($plugin['replacement']) && !isset($plugin['callback']) || isset($plugin['callback']) && !function_exists($plugin['callback'])) {
        drupal_set_message(t('Freelinking plugin "!plugin" is invalid.', array(
          '!plugin' => $name,
        )), 'warning');
        watchdog('filter', 'Freelinking plugin "!plugin" is invalid.', array(
          '!plugin' => $name,
        ), WATCHDOG_WARNING);
      }

      // end if
      // Set "enabled" by format when explicitly set in format configuration..
      $plugin_enabled = variable_get('freelinking_' . $name . '_enabled_format_' . $format, '');
      if ($plugin_enabled) {
        $plugin['enabled'] = $plugin_enabled;
      }

      // Rearrange weight scheme to use core comparison function.
      if (isset($plugin['weight'])) {
        $plugin['#weight'] = $plugin['weight'];
        unset($plugin['weight']);
      }

      // Set explicit defaults.
      $plugin += array(
        'enabled' => TRUE,
        'html' => TRUE,
      );
    }

    // end foreach
    // element_sort() uses '#weight', the hash is added above to support this.
    uasort($freelinking, 'element_sort');
    $plugins[$format] = $freelinking;
  }
  return $plugins[$format];
}