Issue #2225371 by mr.baileys, Wim Leers: Apply formatters and widgets to Custom Block base fields.
parent
d19928b695
commit
8f028bb7d6
|
@ -96,16 +96,6 @@ class CustomBlockFormController extends ContentEntityFormController {
|
|||
// names.
|
||||
$form['#attributes']['class'][0] = drupal_html_class('block-' . $block->bundle() . '-form');
|
||||
|
||||
// Basic block information.
|
||||
$form['info'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Block description'),
|
||||
'#required' => TRUE,
|
||||
'#default_value' => $block->label(),
|
||||
'#weight' => -5,
|
||||
'#description' => $this->t('A brief description of your block. Used on the <a href="@overview">Blocks administration page</a>.', array('@overview' => $this->url('block.admin_display'))),
|
||||
);
|
||||
|
||||
if ($this->moduleHandler->moduleExists('language')) {
|
||||
$language_configuration = language_get_default_configuration('custom_block', $block->bundle());
|
||||
|
||||
|
@ -255,7 +245,7 @@ class CustomBlockFormController extends ContentEntityFormController {
|
|||
$exists = $this->customBlockStorage->loadByProperties(array('info' => $form_state['values']['info']));
|
||||
if (!empty($exists)) {
|
||||
$this->setFormError('info', $form_state, $this->t('A block with description %name already exists.', array(
|
||||
'%name' => $form_state['values']['info'],
|
||||
'%name' => $form_state['values']['info'][0]['value'],
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -177,9 +177,15 @@ class CustomBlock extends ContentEntityBase implements CustomBlockInterface {
|
|||
->setDescription(t('The custom block language code.'));
|
||||
|
||||
$fields['info'] = FieldDefinition::create('string')
|
||||
->setLabel(t('Subject'))
|
||||
->setDescription(t('The custom block name.'))
|
||||
->setRevisionable(TRUE);
|
||||
->setLabel(t('Block description'))
|
||||
->setDescription(t('A brief description of your block.'))
|
||||
->setRevisionable(TRUE)
|
||||
->setRequired(TRUE)
|
||||
->setDisplayOptions('form', array(
|
||||
'type' => 'string',
|
||||
'weight' => -5,
|
||||
))
|
||||
->setDisplayConfigurable('form', TRUE);
|
||||
|
||||
$fields['type'] = FieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Block type'))
|
||||
|
|
|
@ -60,14 +60,14 @@ class CustomBlockCreationTest extends CustomBlockTestBase {
|
|||
|
||||
// Create a block.
|
||||
$edit = array();
|
||||
$edit['info'] = 'Test Block';
|
||||
$edit['info[0][value]'] = 'Test Block';
|
||||
$edit['body[0][value]'] = $this->randomName(16);
|
||||
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
|
||||
|
||||
// Check that the Basic block has been created.
|
||||
$this->assertRaw(format_string('!block %name has been created.', array(
|
||||
'!block' => 'Basic block',
|
||||
'%name' => $edit["info"]
|
||||
'%name' => $edit['info[0][value]']
|
||||
)), 'Basic block created.');
|
||||
|
||||
// Change the view mode.
|
||||
|
@ -82,7 +82,7 @@ class CustomBlockCreationTest extends CustomBlockTestBase {
|
|||
$this->assertOption('edit-settings-custom-block-view-mode', 'default', 'The default view mode is available.');
|
||||
|
||||
// Check that the block exists in the database.
|
||||
$blocks = entity_load_multiple_by_properties('custom_block', array('info' => $edit['info']));
|
||||
$blocks = entity_load_multiple_by_properties('custom_block', array('info' => $edit['info[0][value]']));
|
||||
$block = reset($blocks);
|
||||
$this->assertTrue($block, 'Custom Block found in database.');
|
||||
|
||||
|
@ -92,7 +92,7 @@ class CustomBlockCreationTest extends CustomBlockTestBase {
|
|||
|
||||
// Check that the Basic block has been created.
|
||||
$this->assertRaw(format_string('A block with description %name already exists.', array(
|
||||
'%name' => $edit["info"]
|
||||
'%name' => $edit['info[0][value]']
|
||||
)));
|
||||
$this->assertResponse(200);
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ class CustomBlockCreationTest extends CustomBlockTestBase {
|
|||
*/
|
||||
public function testDefaultCustomBlockCreation() {
|
||||
$edit = array();
|
||||
$edit['info'] = $this->randomName(8);
|
||||
$edit['info[0][value]'] = $this->randomName(8);
|
||||
$edit['body[0][value]'] = $this->randomName(16);
|
||||
// Don't pass the custom block type in the url so the default is forced.
|
||||
$this->drupalPostForm('block/add', $edit, t('Save'));
|
||||
|
@ -113,11 +113,11 @@ class CustomBlockCreationTest extends CustomBlockTestBase {
|
|||
// Check that the block has been created and that it is a basic block.
|
||||
$this->assertRaw(format_string('!block %name has been created.', array(
|
||||
'!block' => 'Basic block',
|
||||
'%name' => $edit["info"],
|
||||
'%name' => $edit['info[0][value]'],
|
||||
)), 'Basic block created.');
|
||||
|
||||
// Check that the block exists in the database.
|
||||
$blocks = entity_load_multiple_by_properties('custom_block', array('info' => $edit['info']));
|
||||
$blocks = entity_load_multiple_by_properties('custom_block', array('info' => $edit['info[0][value]']));
|
||||
$block = reset($blocks);
|
||||
$this->assertTrue($block, 'Default Custom Block found in database.');
|
||||
}
|
||||
|
@ -165,15 +165,15 @@ class CustomBlockCreationTest extends CustomBlockTestBase {
|
|||
public function testBlockDelete() {
|
||||
// Create a block.
|
||||
$edit = array();
|
||||
$edit['info'] = $this->randomName(8);
|
||||
$edit['info[0][value]'] = $this->randomName(8);
|
||||
$body = $this->randomName(16);
|
||||
$edit['body[0][value]'] = $body;
|
||||
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
|
||||
|
||||
// Place the block.
|
||||
$instance = array(
|
||||
'id' => drupal_strtolower($edit['info']),
|
||||
'settings[label]' => $edit['info'],
|
||||
'id' => drupal_strtolower($edit['info[0][value]']),
|
||||
'settings[label]' => $edit['info[0][value]'],
|
||||
'region' => 'sidebar_first',
|
||||
);
|
||||
$block = entity_load('custom_block', 1);
|
||||
|
@ -194,11 +194,11 @@ class CustomBlockCreationTest extends CustomBlockTestBase {
|
|||
$this->assertText(format_plural(1, 'This will also remove 1 placed block instance.', 'This will also remove @count placed block instance.'));
|
||||
|
||||
$this->drupalPostForm(NULL, array(), 'Delete');
|
||||
$this->assertRaw(t('Custom block %name has been deleted.', array('%name' => $edit['info'])));
|
||||
$this->assertRaw(t('Custom block %name has been deleted.', array('%name' => $edit['info[0][value]'])));
|
||||
|
||||
// Create another block and force the plugin cache to flush.
|
||||
$edit2 = array();
|
||||
$edit2['info'] = $this->randomName(8);
|
||||
$edit2['info[0][value]'] = $this->randomName(8);
|
||||
$body2 = $this->randomName(16);
|
||||
$edit2['body[0][value]'] = $body2;
|
||||
$this->drupalPostForm('block/add/basic', $edit2, t('Save'));
|
||||
|
@ -208,7 +208,7 @@ class CustomBlockCreationTest extends CustomBlockTestBase {
|
|||
// Create another block with no instances, and test we don't get a
|
||||
// confirmation message about deleting instances.
|
||||
$edit3 = array();
|
||||
$edit3['info'] = $this->randomName(8);
|
||||
$edit3['info[0][value]'] = $this->randomName(8);
|
||||
$body = $this->randomName(16);
|
||||
$edit3['body[0][value]'] = $body;
|
||||
$this->drupalPostForm('block/add/basic', $edit3, t('Save'));
|
||||
|
|
|
@ -95,7 +95,7 @@ class CustomBlockFieldTest extends CustomBlockTestBase {
|
|||
// Create a block.
|
||||
$this->drupalGet('block/add/link');
|
||||
$edit = array(
|
||||
'info' => $this->randomName(8),
|
||||
'info[0][value]' => $this->randomName(8),
|
||||
$this->field->getName() . '[0][url]' => 'http://example.com',
|
||||
$this->field->getName() . '[0][title]' => 'Example.com'
|
||||
);
|
||||
|
@ -104,8 +104,8 @@ class CustomBlockFieldTest extends CustomBlockTestBase {
|
|||
$url = 'admin/structure/block/add/custom_block:' . $block->uuid() . '/' . \Drupal::config('system.theme')->get('default');
|
||||
// Place the block.
|
||||
$instance = array(
|
||||
'id' => drupal_strtolower($edit['info']),
|
||||
'settings[label]' => $edit['info'],
|
||||
'id' => drupal_strtolower($edit['info[0][value]']),
|
||||
'settings[label]' => $edit['info[0][value]'],
|
||||
'region' => 'sidebar_first',
|
||||
);
|
||||
$this->drupalPostForm($url, $instance, t('Save block'));
|
||||
|
|
|
@ -63,7 +63,7 @@ class CustomBlockListTest extends WebTestBase {
|
|||
$this->clickLink($link_text);
|
||||
$this->assertResponse(200);
|
||||
$edit = array();
|
||||
$edit['info'] = $label;
|
||||
$edit['info[0][value]'] = $label;
|
||||
$edit['body[0][value]'] = $this->randomName(16);
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
|
||||
|
@ -90,7 +90,7 @@ class CustomBlockListTest extends WebTestBase {
|
|||
$this->clickLink(t('Edit'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertTitle(strip_tags(t('Edit custom block %label', array('%label' => $label)) . ' | Drupal'));
|
||||
$edit = array('info' => $new_label);
|
||||
$edit = array('info[0][value]' => $new_label);
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -99,6 +99,20 @@ class CustomBlockTranslationUITest extends ContentTranslationUITest {
|
|||
return array('info' => $this->name) + parent::getNewEntityValues($langcode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an edit array containing the values to be posted.
|
||||
*/
|
||||
protected function getEditValues($values, $langcode, $new = FALSE) {
|
||||
$edit = parent::getEditValues($values, $langcode, $new);
|
||||
foreach ($edit as $property => $value) {
|
||||
if ($property == 'info') {
|
||||
$edit['info[0][value]'] = $value;
|
||||
unset($edit[$property]);
|
||||
}
|
||||
}
|
||||
return $edit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that no metadata is stored for a disabled bundle.
|
||||
*/
|
||||
|
|
|
@ -178,15 +178,15 @@ class CustomBlockTypeTest extends CustomBlockTestBase {
|
|||
$this->clickLink('foo');
|
||||
}
|
||||
// Create a new block.
|
||||
$edit = array('info' => $this->randomName(8));
|
||||
$edit = array('info[0][value]' => $this->randomName(8));
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$blocks = $storage->loadByProperties(array('info' => $edit['info']));
|
||||
$blocks = $storage->loadByProperties(array('info' => $edit['info[0][value]']));
|
||||
if (!empty($blocks)) {
|
||||
$block = reset($blocks);
|
||||
$destination = 'admin/structure/block/add/custom_block:' . $block->uuid() . '/' . $theme;
|
||||
$this->assertUrl(url($destination, array('absolute' => TRUE)));
|
||||
$this->drupalPostForm(NULL, array(), t('Save block'));
|
||||
$this->assertUrl(url("admin/structure/block/list/$theme", array('absolute' => TRUE, 'query' => array('block-placement' => drupal_html_class($edit['info'])))));
|
||||
$this->assertUrl(url("admin/structure/block/list/$theme", array('absolute' => TRUE, 'query' => array('block-placement' => drupal_html_class($edit['info[0][value]'])))));
|
||||
}
|
||||
else {
|
||||
$this->fail('Could not load created block.');
|
||||
|
@ -199,9 +199,9 @@ class CustomBlockTypeTest extends CustomBlockTestBase {
|
|||
$this->drupalGet('admin/structure/block/custom-blocks');
|
||||
$this->clickLink(t('Add custom block'));
|
||||
$this->clickLink('foo');
|
||||
$edit = array('info' => $this->randomName(8));
|
||||
$edit = array('info[0][value]' => $this->randomName(8));
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$blocks = $storage->loadByProperties(array('info' => $edit['info']));
|
||||
$blocks = $storage->loadByProperties(array('info' => $edit['info[0][value]']));
|
||||
if (!empty($blocks)) {
|
||||
$destination = 'admin/structure/block/custom-blocks';
|
||||
$this->assertUrl(url($destination, array('absolute' => TRUE)));
|
||||
|
|
|
@ -31,16 +31,16 @@ class PageEditTest extends CustomBlockTestBase {
|
|||
public function testPageEdit() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
$title_key = 'info';
|
||||
$title_key = 'info[0][value]';
|
||||
$body_key = 'body[0][value]';
|
||||
// Create block to edit.
|
||||
$edit = array();
|
||||
$edit['info'] = drupal_strtolower($this->randomName(8));
|
||||
$edit['info[0][value]'] = drupal_strtolower($this->randomName(8));
|
||||
$edit[$body_key] = $this->randomName(16);
|
||||
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
|
||||
|
||||
// Check that the block exists in the database.
|
||||
$blocks = \Drupal::entityQuery('custom_block')->condition('info', $edit['info'])->execute();
|
||||
$blocks = \Drupal::entityQuery('custom_block')->condition('info', $edit['info[0][value]'])->execute();
|
||||
$block = entity_load('custom_block', reset($blocks));
|
||||
$this->assertTrue($block, 'Custom block found in database.');
|
||||
|
||||
|
@ -59,7 +59,7 @@ class PageEditTest extends CustomBlockTestBase {
|
|||
// Edit the same block, creating a new revision.
|
||||
$this->drupalGet("block/" . $block->id());
|
||||
$edit = array();
|
||||
$edit['info'] = $this->randomName(8);
|
||||
$edit['info[0][value]'] = $this->randomName(8);
|
||||
$edit[$body_key] = $this->randomName(16);
|
||||
$edit['revision'] = TRUE;
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
|
|
Loading…
Reference in New Issue