Skip to content

Instantly share code, notes, and snippets.

@EclipseGc
Created August 14, 2012 03:09
Show Gist options
  • Save EclipseGc/3345999 to your computer and use it in GitHub Desktop.
Save EclipseGc/3345999 to your computer and use it in GitHub Desktop.
diff --git a/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php b/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php
index e245874..8670dd9 100644
--- a/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php
+++ b/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php
@@ -67,10 +67,11 @@ class DerivativeDiscoveryDecorator implements DiscoveryInterface {
foreach ($base_plugin_definitions as $base_plugin_id => $plugin_definition) {
$derivative_fetcher = $this->getDerivativeFetcher($base_plugin_id, $plugin_definition);
if ($derivative_fetcher) {
- $derivative_definitions = $derivative_fetcher->getDerivativeDefinitions($plugin_definition);
- foreach ($derivative_definitions as $derivative_id => $derivative_definition) {
- $plugin_id = $this->encodePluginId($base_plugin_id, $derivative_id);
- $plugin_definitions[$plugin_id] = $derivative_definition;
+ if ($derivative_definitions = $derivative_fetcher->getDerivativeDefinitions($plugin_definition)) {
+ foreach ($derivative_definitions as $derivative_id => $derivative_definition) {
+ $plugin_id = $this->encodePluginId($base_plugin_id, $derivative_id);
+ $plugin_definitions[$plugin_id] = $derivative_definition;
+ }
}
}
else {
diff --git a/core/modules/block/block.admin.inc b/core/modules/block/block.admin.inc
index 92ebc88..6b356f9 100644
--- a/core/modules/block/block.admin.inc
+++ b/core/modules/block/block.admin.inc
@@ -296,13 +296,23 @@ function block_admin_configure_submit($form, &$form_state) {
* @see block_add_block_form_submit()
* @ingroup forms
*/
-function block_add_block_form($form, &$form_state) {
+function block_library_block_form($form, &$form_state) {
$blocks = block_manager()->getDefinitions();
- $options = array();
+ $form['block'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Search'),
+ '#autocomplete_path' => 'block/autocomplete',
+ );
+ $rows = array();
foreach ($blocks as $plugin_id => $config) {
- $options[$plugin_id] = $config['subject'];
+ $row = array($config['subject'], isset($config['description']) ? $config['description'] : '', l('Configure & Place Block', 'admin/block/add/' . $plugin_id));
+ $rows[] = $row;
}
- $form['block'] = array(
+ $form['block_library'] = array(
+ '#type' => 'markup',
+ '#markup' => theme('table', array('header' => array(t('Subject'), t('Description'), t('Operations')), 'rows' => $rows)),
+ );
+ /*$form['block'] = array(
'#title' => t('Select a new block instance.'),
'#type' => 'select',
'#options' => $options,
@@ -310,7 +320,7 @@ function block_add_block_form($form, &$form_state) {
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Next'),
- );
+ );*/
return $form;
}
diff --git a/core/modules/block/block.module b/core/modules/block/block.module
index 6308fc4..3402664 100644
--- a/core/modules/block/block.module
+++ b/core/modules/block/block.module
@@ -58,10 +58,10 @@ function block_help($path, $arg) {
$output .= '<dt>' . t('Controlling visibility') . '</dt>';
$output .= '<dd>' . t('Blocks can be configured to be visible only on certain pages, only to users of certain roles, or only on pages displaying certain <a href="@content-type">content types</a>. Administrators can also allow specific blocks to be enabled or disabled by users when they edit their <a href="@user">My account</a> page. Some dynamic blocks, such as those generated by modules, will be displayed only on certain pages.', array('@content-type' => url('admin/structure/types'), '@user' => url('user'))) . '</dd>';
$output .= '<dt>' . t('Creating custom blocks') . '</dt>';
- $output .= '<dd>' . t('Users with the <em>Administer blocks</em> permission can <a href="@block-add">add custom blocks</a>, which are then listed on the <a href="@blocks">Blocks administration page</a>. Once created, custom blocks behave just like default and module-generated blocks.', array('@blocks' => url('admin/structure/block'), '@block-add' => url('admin/structure/block/add'))) . '</dd>';
+ $output .= '<dd>' . t('Users with the <em>Administer blocks</em> permission can <a href="@block-add">add custom blocks</a>, which are then listed on the <a href="@blocks">Blocks administration page</a>. Once created, custom blocks behave just like default and module-generated blocks.', array('@blocks' => url('admin/structure/block'), '@block-add' => url('admin/structure/block/library'))) . '</dd>';
$output .= '</dl>';
return $output;
- case 'admin/structure/block/add':
+ case 'admin/structure/block/library':
return '<p>' . t('Use this page to create a new custom block.') . '</p>';
}
if ($arg[0] == 'admin' && $arg[1] == 'structure' && $arg['2'] == 'block' && (empty($arg[3]) || $arg[3] == 'list')) {
@@ -135,10 +135,10 @@ function block_menu() {
'context' => MENU_CONTEXT_NONE,
'file' => 'block.admin.inc',
);
- $items['admin/structure/block/add'] = array(
- 'title' => 'Add block',
+ $items['admin/structure/block/library'] = array(
+ 'title' => 'Block Library',
'page callback' => 'drupal_get_form',
- 'page arguments' => array('block_add_block_form'),
+ 'page arguments' => array('block_library_block_form'),
'access arguments' => array('administer blocks'),
'type' => MENU_LOCAL_ACTION,
'file' => 'block.admin.inc',
@@ -155,9 +155,9 @@ function block_menu() {
);
if ($key != $default_theme) {
$items['admin/structure/block/list/' . $key . '/add'] = array(
- 'title' => 'Add block',
+ 'title' => 'Block Library',
'page callback' => 'drupal_get_form',
- 'page arguments' => array('block_add_block_form'),
+ 'page arguments' => array('block_library_block_form'),
'access arguments' => array('administer blocks'),
'type' => MENU_LOCAL_ACTION,
'file' => 'block.admin.inc',
@@ -175,9 +175,29 @@ function block_menu() {
'file' => 'block.admin.inc',
);
}
+ $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);
+}
+
/**
* Access callback: Only enabled themes can be accessed.
*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment