function system_plugin_autocomplete

Page callback: Autocompletes any plugin system tied to a plugin UI plugin.

The passed plugin_id indicates the specific plugin_ui plugin that is in use here. The documentation within the annotation of that plugin will contain a manager for the plugins that need to be autocompleted allowing this function to autocomplete plugins for any plugin type.

Parameters

$plugin_id: The plugin id for the calling plugin.

Return value

object JsonResponse

1 string reference to 'system_plugin_autocomplete'
system_menu in drupal/core/modules/system/system.module
Implements hook_menu().

File

drupal/core/modules/system/system.module, line 1085
Configuration system that lets administrators modify the workings of the site.

Code

function system_plugin_autocomplete($plugin_id) {
  $string_typed = drupal_container()
    ->get('request')->query
    ->get('q');
  $string_typed = drupal_explode_tags($string_typed);
  $string = drupal_strtolower(array_pop($string_typed));
  $matches = array();
  if ($string) {
    $plugin_ui = Drupal::service('plugin.manager.system.plugin_ui')
      ->getDefinition($plugin_id);
    $manager = Drupal::service($plugin_ui['manager']);
    $titles = array();
    foreach ($manager
      ->getDefinitions() as $plugin_id => $plugin) {
      $titles[$plugin_id] = $plugin[$plugin_ui['title_attribute']];
    }
    $matches = preg_grep("/\\b" . $string . "/i", $titles);
  }
  return new JsonResponse($matches);
}