Skip to content

Instantly share code, notes, and snippets.

@EclipseGc
Created September 5, 2012 20:02
Show Gist options
  • Save EclipseGc/3643652 to your computer and use it in GitHub Desktop.
Save EclipseGc/3643652 to your computer and use it in GitHub Desktop.
/**
* A generic autocomplete page callback for any plugin system tied to a plugin
* ui plugin.
*/
function system_plugin_autocomplete($plugin_id, $string = '') {
$matches = array();
$ui = system_plugin_manager('plugin_ui')->getDefinition($plugin_id);
$manager = new $ui['manager']();
if ($string) {
$plugins = $manager->getDefinitions();
$titles = array();
foreach($plugins as $plugin_id => $plugin) {
$titles[$plugin_id] = $plugin[$ui['title_attribute']];
}
$matches = preg_grep("/\b". $string . "/i", $titles);
}
return new JsonResponse($matches);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment