Problem/Motivation
To reproduce:
Using Drupal 8.8.x, Standard
- Enable Layout Builder and override on Basic page
- Add a node
- Override the node layout and add a Basic block inline block with the title Testing
- Save the layout.
- Add a new block on admin/structure/block/block-content and use Testing as block description.
Current behaviour:
You will now get the error: A custom block with block description Testing already exists.
However, since the block is non-reusable and a composite of that node it will not be listed in the Custom block library.
Expected behaviour:
The block should have been created.
Layout Builder / non-reusable blocks seems to ignore the UniqueField constraint on the label (which is probably correct) but it should not conflict with reusable content blocks because they are distinguished.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comments
Comment #2
johnwebdev commentedComment #3
johnwebdev commentedFailing test
Comment #5
tedbowThe
testValidation()method in this class already check for the validation message so I think we could just add this to the existing test and do another case where it should not exist.UniqueBlockContentLabelValueValidator. I have changedUniqueFieldValueValidatorto add agetEntityQuery()method. This allows use to extend this and just add$query->condition('reusable', 1);We could also just copy logic from
UniqueFieldValueValidatorand not extend it. But it seems useful to have a "unique with conditions" ability in other validators.Comment #6
bkosborneThis works as expected and solves the problem for us! Thank you!
Comment #7
tedbowpatch doesn't apply anymore
Comment #8
tedbowreroll
Comment #9
nghai commentedHey @tedbow
Hunk #3 FAILED at 55.
1 out of 3 hunks FAILED -- saving rejects to file core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/UniqueFieldValueValidator.php.rej
without the patch the translations works fine.
Tested with Drupal 8.7.5, with layouts builders + multi-lingual
UPDATE: the patch 3054197-8 not failing with core 8.8.x
Comment #10
nghai commentedAs mentioned here and from above comment
The BlockContentInlineBlockTranslateForm also validates using an _entity_form with BlockContent.php as entity type, which is not the case for creating and updating InlineBlock originally.
It would be ideal to validate the block_content only if there are reusable. Attaching the patch and interdiff to review.
And the above patch 3054197-8 is not failing with 8.8.x.
Comment #12
capysara commentedI'm not sure how to test the translation part, but the patch in #10 applies and works for 8.9.
Comment #14
janmejaig commentedI have verified the above ticket and found that it is working fine on Drupal 9.1.x as expected. This seems to be working as expected without applying patch.
Comment #16
abhijith s commentedApplied patch #10 on 9.2.x and it doesn't fix this issue.I'm still getting that error after applying this patch.
Comment #17
abhijith s commentedComment #18
vakulrai commentedAbhijith S, I check the scenario like below and seems to be working as expected:
I think you must be testing it by directly adding it form custom blocks, that's why its giving validation error, please check this: Allow Custom blocks to be set as non-reusable adding access restriction based on where it was used.
Thanks
Comment #19
vakulrai commentedRerolled for 9.2.x, #10 was failing to apply cleanly.
This statement was failing the patch.
Thanks.
Comment #22
bkosborneI was thinking - why do we even force block titles to be unique at all? I did some searching and finally found the source of this: #1998658: Creating Custom Block with same name as existing block throws SQL error
I have to dig more - but I don't think that SQL error is still relevant? There's nothing in the database table that indicates it must be unique.
Maybe we should instead just open a separate issue to allow blocks to have duplicate titles? Why should content blocks be any different than Nodes in this regard (which allow duplicate titles).
Comment #23
ranjith_kumar_k_u commentedRe-rolled #19 for 9.4
Comment #24
devashish jangid commentedDrupal 9.4.x-dev
Verified and tested patch #23.
Patch applied successfully and looks good for me.
Sharing screenshot for the reference.
Moving this ticket to RTBC.
Comment #25
lobsterr commentedAfter investigation I found the UniqueField constraint is useless and it is an heritage from the old custom block module. More info could be found here:
#3272969: Remove unique constraint on block content info field
Comment #27
smustgrave commentedWondering if this is still an issue if the unique constraint is dropped in https://www.drupal.org/project/drupal/issues/3272969
Comment #28
smustgrave commentedAfter speaking with @larowlan on slack.
And in https://www.drupal.org/project/drupal/issues/3272969 we are removing the constraint. So closing out as duplicate.