Commit 75df269a authored by webchick's avatar webchick

Issue #1880378 by swentel, EclipseGc: Fixed Autocomplete broken to search...

Issue #1880378 by swentel, EclipseGc: Fixed Autocomplete broken to search blocks - also triggers notice after clicking 'Next'.
parent 55d72f73
......@@ -44,10 +44,19 @@ class BlockPluginUI extends PluginUIBase {
*/
public function form($form, &$form_state, $facet = NULL) {
// @todo Add an inline comment here.
list($plugin, $theme) = explode(':', $this->getPluginId());
$plugin_definition = $this->getDefinition();
$manager = new $plugin_definition['manager']();
$plugins = $manager->getDefinitions();
$form['#theme'] = 'system_plugin_ui_form';
$form['theme'] = array(
'#type' => 'value',
'#value' => $theme,
);
$form['manager'] = array(
'#type' => 'value',
'#value' => $manager,
);
$form['instance'] = array(
'#type' => 'value',
'#value' => $this,
......@@ -93,6 +102,16 @@ public function form($form, &$form_state, $facet = NULL) {
return $form;
}
/**
* Overrides \Drupal\system\Plugin\PluginUIBase::formValidate().
*/
public function formValidate($form, &$form_state) {
$definitions = $form_state['values']['manager']->getDefinitions();
if (!isset($definitions[$form_state['values']['block']])) {
form_set_error('block', t('You must select a valid block.'));
}
}
/**
* Overrides \Drupal\system\Plugin\PluginUIBase::formSubmit().
*/
......
<?php
/**
* @file
* Contains \Drupal\block\Tests\BlockLibrarySearchTest.
*/
namespace Drupal\block\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests the block library search.
*/
class BlockLibrarySearchTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('block');
/**
* An administrative user to configure the test environment.
*/
protected $adminUser;
public static function getInfo() {
return array(
'name' => 'Block library search',
'description' => 'Checks that the block library search works correctly.',
'group' => 'Block',
);
}
protected function setUp() {
parent::setUp();
// Create and log in an administrative user.
$this->adminUser = $this->drupalCreateUser(array(
'administer blocks',
'access administration pages',
));
$this->drupalLogin($this->adminUser);
}
/**
* Test block library search.
*/
function testBlockLibrarySearch() {
// Check that the block plugin is valid.
$this->drupalPost('admin/structure/block/list/block_plugin_ui:stark/add', array('block' => 'invalid_block'), t('Next'));
$this->assertText('You must select a valid block.');
// Check that the block search form redirects to the correct block form.
$this->drupalPost('admin/structure/block/list/block_plugin_ui:stark/add', array('block' => 'system_main_block'), t('Next'));
$this->assertUrl('admin/structure/block/manage/system_main_block/stark');
}
}
......@@ -1119,9 +1119,20 @@ function system_plugin_ui_form($form, &$form_state, $plugin, $facet = NULL) {
/**
* Page callback: Autocompletes any plugin system tied to a plugin UI plugin.
*
* @todo This needs more explanation and parameter documentation.
* The passed plugin_id indicates the specific plugin_ui plugin that is in use
* here. The documentation within the annotation of that plugin will contain a
* manager for the plugins that need to be autocompleted allowing this function
* to autocomplete plugins for any plugin type.
*
* @param $plugin_id
* The plugin id for the calling plugin.
*
* @return object JsonResponse
*/
function system_plugin_autocomplete($plugin_id, $string = '') {
function system_plugin_autocomplete($plugin_id) {
$string_typed = drupal_container()->get('request')->query->get('q');
$string_typed = drupal_explode_tags($string_typed);
$string = drupal_strtolower(array_pop($string_typed));
$matches = array();
if ($string) {
$plugin_ui = drupal_container()->get('plugin.manager.system.plugin_ui')->getDefinition($plugin_id);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment