You are here

function mpac_get_selection_handlers in Multi-path autocomplete 8

Gets the selection handlers for a given mpac autocomplete type.

Parameters

string $type: Type of handlers to load (i.e. "path").

Return value

array List of \Drupal\mpac\Plugin\Type\Selection\SelectionInterface.

1 call to mpac_get_selection_handlers()
MpacAutocomplete::getMatches in lib/Drupal/mpac/MpacAutocomplete.php
Get matches for the autocompletion.

File

./mpac.module, line 30
Find node paths on menu item creation via autocomplete.

Code

function mpac_get_selection_handlers($type) {
  $handlers = array();
  $plugin_manager = \Drupal::service('plugin.manager.mpac.selection');

  // Load all available plugins.
  $plugins = $plugin_manager
    ->getDefinitions();

  // Sort the selection plugins by weight.
  uasort($plugins, array(
    'Drupal\\Component\\Utility\\SortArray',
    'sortByWeightElement',
  ));
  foreach ($plugins as $key => $plugin_info) {
    if (!empty($plugin_info['types']) && count(array_intersect(array(
      $type,
      '*',
    ), $plugin_info['types'])) > 0) {
      $plugin = $plugin_manager
        ->createInstance($plugin_info['id']);
      $handlers[$key] = $plugin;
    }
  }

  // Allow other modules to alter the list of handlers for a type.
  \Drupal::moduleHandler()
    ->alter('mpac_selection_handlers', $handlers, $type);
  return $handlers;
}