Skip to content

Instantly share code, notes, and snippets.

@EclipseGc
Created August 14, 2012 02:37
Show Gist options
  • Save EclipseGc/3345865 to your computer and use it in GitHub Desktop.
Save EclipseGc/3345865 to your computer and use it in GitHub Desktop.
<?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