Process:
1) Create custom block type.
2) Create a new block, of that new block type just created. [Give the block a title that contains a '.'] Example title: "This.is custom"
3) Go to block layout, and place that new block, in a region.
4) Place that same block in an additional region.. The error will occur at this point.
Drupal Will Log this error:
Drupal\Core\Entity\EntityStorageException: 'block' entity with ID 'moregreatpeople...' already exists. in Drupal\Core\Entity\EntityStorageBase->doPreSave() (line 430 of /Users/micahjoyner/www/cmm.dev/core/lib/Drupal/Core/Entity/EntityStorageBase.php).
So, it appears that it can't seem to create a proper unique ID, for any additionally place block, if the title contains a period in it.
Comment | File | Size | Author |
---|---|---|---|
#27 | after-block-page-save.png | 65.98 KB | Tom M Fallon |
#26 | 2685917-block-period-exception.26.patch | 4.37 KB | Munavijayalakshmi |
#11 | 2685917-block-period-exception.11.patch | 4.36 KB | larowlan |
#11 | 2685917-block-period-exception.test-only.patch | 3.07 KB | larowlan |
#11 | interdiff.txt | 2.54 KB | larowlan |
Comments
Comment #2
larowlanComment #3
cilefen CreditAttribution: cilefen commentedComment #4
markconroy CreditAttribution: markconroy as a volunteer and at Annertech commentedHi guys,
Just confirming this bug. My steps to reproduce:
- A block named 1.3.1 was placed in a region.
- Set that block to 'none' (so it's placed in 'Disabled').
- Try to place that block in a region using the 'Place block' widget on the /admin/structure/blocks/ page at the desired region
- Error message: 'The website has encountered an unexpected error'.
- Log message: 'Drupal\Core\Entity\EntityStorageException: 'block' entity with ID '1.3.1abovecontent' already exists. in Drupal\Core\Entity\EntityStorageBase->doPreSave() (line 430 of /Users/markconroy/htdocs/adesignforlife/envato/adfl-alpha/docrooot/core/lib/Drupal/Core/Entity/EntityStorageBase.php).'
Note: If I got to the 'Disabled' section on the blocks page and choose the region I want the block to appear, it works fine from there. But I can't enable any other blocks (more than once) that also have a full stop/period in their names.
Comment #5
larowlanComment #6
larowlanThe issue here is that
\Drupal\block\BlockForm::getUniqueMachineName
treats the.
as a config delimiter.Simple fix is to disallow the
.
from block IDs. That makes sense anyway as it would mess with the config system, where the.
has significance.Failing test and fix.
Comment #8
tim.plunkettShouldn't this be block_content, not block?
descriptiveTestMethodNamesAreTheBest
Why not just use a string with the known result of this?
Fix looks good!
Comment #9
larowlan1) no, the bug is in BlockForm and BlockBase
2) :)
3) BlockBase::getMachineNameSuggestion is protected, I guess I could use reflection and call it instead of this dance, I have the plugin from $block->getPlugin() - thoughts?
Comment #10
tim.plunkett1) Duh, of course. Thanks :)
3) I'm not averse to reflection in tests, so that wfm. I think it will be clearer.
Comment #11
larowlanMoved to reflection approach.
Also added user entity for 8.2/8.3 where we have a revision user for block content.
Comment #14
tim.plunkettI think that is much clearer. Thanks!
Comment #16
catchFixed some unused use statements on commit to 8.3.x
Leaving RTBC against 8.2.x, nice find.
Comment #17
xjmI get nervous when I see support for something removed without an explanation of why it was there to begin with. I remember in the original BAP conversion that there was a whole lot of work specifically around supporting that dot operator. #2043527: Theme name is included in block machine name but should be stored as a key instead removed the pseudo-namespacing-by-theme from block instances and therefore the need for it.
However, what happens if someone has an existing block instance with the dot in its macine name on their site following this patch?
Comment #18
xjmOops, did not mean to change the branch.
Comment #20
catchThat's a good question, we need an upgrade path for existing blocks at a minimum. Reverted for now.
Comment #21
Londova CreditAttribution: Londova commented+
Comment #22
Dinesh18 CreditAttribution: Dinesh18 as a volunteer and at TATA Consultancy Services for Pfizer, Inc. commentedI have checked and able to replicate the issue. I would suggest, if we can add a validation so that it would not allow period to add in Block Title. If you can check any of the contributed blocks placed doesn't have any period.
Comment #26
Munavijayalakshmi CreditAttribution: Munavijayalakshmi at Valuebound commentedRerolled the patch.
Comment #27
Tom M Fallon CreditAttribution: Tom M Fallon as a volunteer and at CTI Digital commentedHello
Just tested #26 2685917-block-period-exception.26.patch
1) Installed Drupal Core 8.3.x
2) Applied Patch successfully
3) Created a block called "This.is custom" and added to "Breadcrumb" region
4) Created a second block called "This.is custom2" and added to "Content" Region
5) Clicked Save
6) This saves successfully with no errors shown and no errors shown in logs.
Screen shot of success page
Comment #28
Tom M Fallon CreditAttribution: Tom M Fallon as a volunteer and at CTI Digital commentedComment #29
alexpottThere's still no update path as per #17 and #20. As per #17 I think we need to support dots in custom block titles and work out why this is happening and fix in a different way.
Comment #31
subhojit777I was also seeing this error in Drupal 8.3.2. There were two breadcrumb blocks created, but they were placed in different regions. One of the block was disabled. And while I was installing a module I was getting
Drupal\Core\Entity\EntityStorageException: 'block' entity with ID 'custom_admin_theme_breadcrumb...' already exists. in Drupal\Core\Entity\EntityStorageBase->doPreSave() (line 430 of /Users/micahjoyner/www/cmm.dev/core/lib/Drupal/Core/Entity/EntityStorageBase.php).
After I deleted the disabled block, the theme installed without any error.
Comment #40
quietone CreditAttribution: quietone at PreviousNext commentedI tested this on Drupal 10.1.x, standard install and was not able to reproduce the problem.
The patch here is fixing this by changing code in /core/lib/Drupal/Core/Block/BlockBase.php. That code was removed in #3091309: Broken context-aware block plugins throw an unexpected exception. I suspect this was fixed by that but can't be sure.
Therefore, closing as outdated. If you are experiencing this problem on a supported version of Drupal reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue (starting from "Install Drupal core").
Thanks!