You are here

function freelinking_get_plugins in Freelinking 7.3

Same name and namespace in other branches
  1. 6.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.

4 calls to freelinking_get_plugins()
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.
_freelinking_process in ./freelinking.module
Implements filter process callback
_freelinking_tips in ./freelinking.module
Implements filter tips callback
1 string reference to 'freelinking_get_plugins'
hook_freelinking_alter in ./freelinking.api.php

File

./freelinking.utilities.inc, line 78
Freelinking ver. 3 Utilities

Code

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

    // 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 defaults (will not overwrite key already set).
      $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];
}