Commit edcc7560 authored by webchick's avatar webchick

Issue #1998658 by larowlan: Fixed Creating Custom Block with same name as...

Issue #1998658 by larowlan: Fixed Creating Custom Block with same name as existing block throws SQL error.
parent 757dbd79
......@@ -219,4 +219,19 @@ public function delete(array $form, array &$form_state) {
$form_state['redirect'] = array('block/' . $block->id() . '/delete', array('query' => $destination));
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, array &$form_state) {
if ($this->entity->isNew()) {
// @todo Inject this once https://drupal.org/node/2060865 is in.
$exists = \Drupal::entityManager()->getStorageController('custom_block')->loadByProperties(array('info' => $form_state['values']['info']));
if (!empty($exists)) {
form_set_error('info', t('A block with description %name already exists.', array(
'%name' => $form_state['values']['info']
)));
}
}
}
}
......@@ -64,6 +64,16 @@ public function testCustomBlockCreation() {
$blocks = entity_load_multiple_by_properties('custom_block', array('info' => $edit['info']));
$block = reset($blocks);
$this->assertTrue($block, 'Custom Block found in database.');
// Check that attempting to create another block with the same value for
// 'info' returns an error.
$this->drupalPost('block/add/basic', $edit, t('Save'));
// Check that the Basic block has been created.
$this->assertRaw(format_string('A block with description %name already exists.', array(
'%name' => $edit["info"]
)));
$this->assertResponse(200);
}
/**
......
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