When creating an image block where the description of the block is the same as an existing block, a PDO Exception is thrown as follows:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'block_name_here' for key 'info': INSERT INTO {imageblock} (body, info, format) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => [:db_insert_placeholder_1] => block_name_here [:db_insert_placeholder_2] => filtered_html ) in imageblock_add_block_form_submit() (line 73 of /sites/all/modules/imageblock/imageblock.admin.inc).
This is confusing for a user, who usually doesn't know why her attempt to create a new image block has failed.
I think a validation handler should be written for the "add image" form which checks whether a block with the same info key exists, and throws a user-friendly form_set_error() if so.
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | imageblock-Message_for_duplicate_image_block_info-2291883-11.patch | 1.3 KB | diegosh |
Comments
Comment #1
diegosh commentedCheck for duplicates block info to prevent a PDO exception and show a message if it's necessary.
Comment #2
diegosh commentedComment #3
diegosh commentedComment #4
ericbobson commentedLooks great!
Suggest you could improve the wording of the error message, e.g.
form_set_error('imageblock', t("Failed to create block. A block with this description already exists. Please edit your block description and try again."));Thanks!
Comment #5
guypaddock commentedThis prevents updating an existing image block.
Comment #6
diegosh commentedComment #7
diegosh commentedComment #9
diegosh commentedComment #10
guypaddock commentedThis still needs work. As I mentioned on 2014-12-22, with this applied, you can no longer update an existing image block -- it blocks the save saying you have a duplicate.
Comment #11
diegosh commentedYou're right.
Iive just added this code snippet and soon i send the patch
if($form['#form_id'] == 'imageblock_add_block_form') {
$info = $form_state['values']['info'];
$duplicate_desc = db_query('SELECT count(info) FROM {imageblock} WHERE info = :info',array(':info'=>$info))->fetchField();
if ($duplicate_desc) {
form_set_error('imageblock_duplicate', t("Failed to create block. A block with this description already exists. Please edit your block description and try again."));
}
}
With this clause only check for new blocks
Comment #12
diegosh commentedComment #13
diegosh commentedComment #15
diegosh commentedI've just committed this change. Many thanks guypaddock feel free to suggest new ideas or improvements.
Comment #16
diegosh commented