You are here

public function FreelinkingManager::getPluginFromIndicator in Freelinking 8.3

Same name and namespace in other branches
  1. 4.0.x src/FreelinkingManager.php \Drupal\freelinking\FreelinkingManager::getPluginFromIndicator()

Get the plugin to use based on the indicator and a list of allowed plugins.

Parameters

string $indicator: The indicator string to test.

array $allowed_plugins: An indexed array of plugin names.

array $options: The settings from the filter. This is an associative array.

Return value

\Drupal\freelinking\Plugin\FreelinkingPluginInterface|false The plugin to use or FALSE if not found.

Overrides FreelinkingManagerInterface::getPluginFromIndicator

See also

\Drupal\freelinking\Plugin\Filter\Freelinking::process()

File

src/FreelinkingManager.php, line 49

Class

FreelinkingManager
Freelinking plugin manager.

Namespace

Drupal\freelinking

Code

public function getPluginFromIndicator($indicator, array $allowed_plugins = [], array $options = []) {
  $current_plugin = FALSE;
  $default_configuration = [
    'settings' => [],
  ];
  try {
    if ('showtext' === $indicator || 'nowiki' === $indicator || 'redact' === $indicator) {
      return $this
        ->createInstance('builtin', []);
    }
    foreach ($allowed_plugins as $plugin_name => $plugin_info) {

      /** @var \Drupal\freelinking\Plugin\FreelinkingPluginInterface $plugin */
      $default_configuration['settings'] = isset($plugin_info['settings']) ? $plugin_info['settings'] : [];
      $plugin = $this
        ->createInstance($plugin_name, $default_configuration);
      if (preg_match($plugin
        ->getIndicator(), $indicator)) {
        $current_plugin = $plugin;
      }
    }

    // Set the current plugin to nodetitle if it is the default.
    if (!$options['global_options']['ignore_upi'] && in_array('nodetitle', $allowed_plugins) && 'nodetitle' === $options['default'] && !$current_plugin) {
      $default_configuration['settings'] = $allowed_plugins['nodetitle']['settings'];
      $current_plugin = $this
        ->createInstance('nodetitle', $default_configuration);
    }
    return $current_plugin;
  } catch (PluginNotFoundException $e) {
    return $current_plugin;
  }
}