Updated: Comment #0
Problem/Motivation
There is code like this scattered throughout core at the moment:
$config_id = explode('.', $block->id());
$machine_name = array_pop($config_id);
list(, $machine_name) = explode('.', $default_theme_block_id);
Whose purpose is to extract the 'powered' from a 'bartik.powered' block ID in order to get the usable "machine name".
Proposed resolution
Remove $theme from the block machine name and store it as a key instead. @tim.plunkett and @xjm said in IRC that config entity query could be useful here.
Remaining tasks
Patch needs to be written.
User interface changes
n/a
API changes
TBD
None yet
Comments
Comment #0.0
star-szrGrammar/phrasing tweak
Comment #1
tim.plunkettWorking on this.
Comment #2
tim.plunkettPreliminary patch. No reviews please, just testing with the bot.
Comment #4
tim.plunkettMissed a couple form keys.
To recap:
When blocks were vanilla CMI and not yet ConfigEntity, we used
config_get_storage_names_with_prefix()to load the blocks of a given theme.Once we switched to ConfigEntity, we just used
entity_load_multiple_by_properties('block', array('theme' => $theme));However, we didn't actually store the theme in the yaml as its own key, and while we added a hack to allow
$block->get('theme')to work,$block->id()always returned the theme prepended to the machine name.Most of this is undoing the explode() calls, and adjusting to $form['machine_name'] becoming $form['id'].
Because we want to have blocks placed more than once per site (aka once per theme, like the main content block), I've kept the theme prefix for all shipped blocks, but with an underscore instead of a dot.
Site builders will need to use their best judgement when naming blocks. There is plenty of work being done to offload that burden anyway.
Comment #6
tim.plunkettI don't have it in me to debug Drupal\system\Tests\Menu\BreadcrumbTest this week. Unassigning so someone else can try fixing it...
Comment #7
tim.plunkettComment #8
tim.plunkettWill work on this soon, possibly this weekend.
Comment #9
tim.plunkettLet's see where this gets us.
Comment #10
tim.plunkettComment #12
tim.plunkettFixed a couple stragglers
Comment #14
tim.plunkettA little overzealous there, we still need the tools block for Seven.
Comment #15
tim.plunkettYay, green! Now it just needs a review.
Comment #16
benjy commentedOK I've looked over the code and everything from your patch seems fine. We do however have a bit of inconsistency throughout with the use of strtolower(), drupal_strtolower() and Unicode::strtolower(), might be worth a follow up to clean them up?
Off Topic
I noticed that if you enable another theme, eg stark, then go back to bartik and add a block into a region stark doesn't have and then re-enable stark the block doesn't land in the default region like it does the first time you enable the theme. Bit of an edge case but it should probably be consistent right?
Comment #17
tim.plunkettNo, that's how it works in D7. Themes can only actually be installed once, "disabling" them is a lie. See #1067408: Themes do not have an installation status
Comment #18
benjy commentedWell it's RTBC for me.
Comment #19
alexpottNeeds a reroll
Comment #20
tim.plunkettBlergh
Comment #21
tim.plunkettConflicted on Plugin/Core/Entity and some added test coverage in the same hunk.
No actual changes.
Comment #23
tim.plunkettDuh, I should have fixed the newly added hunk that broke the patch...
Comment #24
benjy commentedBack to RTBC.
Comment #25
alexpottPatch no longer applies
Comment #26
tim.plunkettRerolled.
Comment #27
alexpottComment #28
tim.plunkettA newly added comment in the patch context. No change.
Comment #29
alexpottPatch no longer applies.
Comment #30
tim.plunkettIt was just s/plugin.manager.entity/entity.manager in patch context, no changes.
Comment #31
alexpottApproving the API change of switching to ID from machine name since a placed block is a config entity and unique loading by it's ID makes perfect sense. This patch is getting rid of code. Yay!
I can't for the life of me see how this code is actually called. Chatted this through with @dawehner on IRC #2022897: Shift responsibility for creating unique config id/machine name off of (views) block plugins and onto BlockFormController and he agrees this is unused. So we have two options here... remove the changes since they're unused and untested or just remove the method as we are cleaning up block ID code here.
Comment #32
dawehnerOh, the default theme is actually stored in system_theme.default
That rename does not fit with the other renames of the files, but sure, the IDs are flexible now.
Comment #33
benjy commentedPatch no longer applies.
Comment #34
vijaycs85Re-roll of #32.
Comment #35
alexpottJust postponed #2100203: Make config entities use dots in machine names consistently on this
Comment #36
vijaycs85Replacing few drupalPost() with drupalPostForm()
Comment #38
tim.plunkettWorking on fixes.
Comment #39
tim.plunkettOnce this is green, let's get it in. Rerolling for added tests is a pain.
Comment #41
tim.plunkettConflicted with #1879396: Add inline documentation to BlockBase::validateConfigurationForm() and BlockBase::submitConfigurationForm(), it documented some of the weirdness we're removing :)
Comment #42
larowlanLooks ok.
I note the comment in WebTestBase::drupalPlaceBlock
Is that no longer relevant? If so we need a follow-up to remove it or if we have to re-roll again, it can be removed here while we're at it.
Comment #43
larowlanscreenshot from manual testing

Comment #44
alexpottThis patch didn't change the fact the current code in drupalPlaceBlock() has made this comment obselete - so out of scope :)
Committed 9fdc6a9 and pushed to 8.x. Thanks!
Comment #45
gábor hojtsySince I have tests failing in config_translation due to this change, I'm trying to understand what happened here... The config file names still use the 'theme.machine_name' construct, while the id of the block is 'theme_machine_name', right? This seems to be the first case, where the id of the config entity would be different from the part of the config file name after the config prefix. Confusing for me :/ Is this intended even?!
Comment #46
gábor hojtsyNote that this is not a theoretical question only. This patch actually broke the translatability support of block placements because the id is not anymore equal to machine name which is not anymore equal to the identifier used in the URL and the file name.
Comment #47
tim.plunkettThe renames got lost since #32.
Comment #48
xanoI manually checked the file renames against the patch from #41 and they match.
Comment #49
alexpottCommitted f36755f and pushed to 8.x. Thanks!
Doh! I should have spotted this.
Comment #50
gábor hojtsyYay, superb, thanks! The config_translation tests caught this. Yet another reason to get the module in core :D
Comment #51
gábor hojtsyOk, well, not good enough yet. The config schema was still not updated. Now the block config files don't have block.block.*.*.yml anymore, but block.block.*.yml. Also the new theme key was not added to the schema.
Yet another reason to add the config translation module to core? :) (Which caught this again through the block translatability test).
Comment #52
larowlanis there an issue to add that? (would like to follow)
Comment #53
gábor hojtsy@larowlan: #1952394: Add configuration translation user interface module in core - already found dozens of bugs in core via that in date formats, comment local tasks, even hook_help :)
Comment #54
vijaycs85#51 looks good.
Comment #55
alexpottCommitted 44639c1 and pushed to 8.x. Thanks!
Comment #56
ianthomas_ukThis makes sense for a property like the block ID, but surely the region, weight and maybe other properties should be theme-specific.
Is it possible to have the same block assigned to different regions in different themes following this patch?
Comment #57
alexpottYes it is possible to have the same block assigned to different regions in different themes
Comment #58.0
(not verified) commentedScattered throughOUT
Comment #59
yched commentedFrom the issue summary:
#2161591: Change default active config from file storage to DB storage is now reopening the two-year old "let's not store config in files" debate under the premise that "To determine which blocks to show on a page we [do an entity query which runs a] query on files on every page load. It's horrible, outdated and slow" :-p
Storing the theme as a property in the yaml was definitely a good thing, but removing it from the entity id & thus from the filename seems to bite us back...