Created
August 14, 2012 02:37
-
-
Save EclipseGc/3345865 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
<?php | |
function block_menu() { | |
$items['block/autocomplete'] = array( | |
'title' => 'Block autocomplete', | |
'page callback' => 'block_autocomplete', | |
'access callback' => 'user_access', | |
'access arguments' => array('administer blocks'), | |
'type' => MENU_CALLBACK, | |
); | |
return $items; | |
} | |
function block_autocomplete($string = '') { | |
$matches = array(); | |
if ($string) { | |
$blocks = block_manager()->getDefinitions(); | |
$block_titles = array(); | |
foreach($blocks as $plugin_id => $block) { | |
$block_titles[$plugin_id] = $block['subject']; | |
} | |
$matches = preg_grep("/^". $string . "/i", $block_titles); | |
} | |
return new JsonResponse($matches); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment