Created
September 5, 2012 20:02
-
-
Save EclipseGc/3643652 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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