Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
This is a follow-up for #2404105: When a profile installs a block for a theme, it is created for all enabled themes.
There we found out when you install a site with some themes enabled. And then add for example claro to the core.extensions
file and execute a drush cim
. Then block_theme_initialize
creates some blocks, but they get immediately deleted.
$ drush cim (9.2.x|✚6…)
+------------+----------------+-----------+
| Collection | Config | Operation |
+------------+----------------+-----------+
| | core.extension | Update |
+------------+----------------+-----------+
Import the listed configuration changes? (yes/no) [yes]:
> y
[notice] Synchronized extensions: install claro.
[notice] Synchronized configuration: delete block.block.claro_tools.
[notice] Synchronized configuration: delete block.block.claro_main_menu.
[notice] Synchronized configuration: delete block.block.claro_footer.
[notice] Synchronized configuration: delete block.block.claro_account_menu.
[notice] Synchronized configuration: delete block.block.claro_branding.
[notice] Synchronized configuration: delete block.block.claro_breadcrumbs.
[notice] Synchronized configuration: delete block.block.claro_content.
[notice] Synchronized configuration: delete block.block.claro_messages.
[notice] Synchronized configuration: delete block.block.claro_powered.
[notice] Synchronized configuration: delete block.block.claro_search.
[notice] Synchronized configuration: delete block.block.claro_help.
[notice] Synchronized configuration: delete claro.settings.
[notice] Synchronized configuration: delete block.block.claro_local_actions.
[notice] Synchronized configuration: delete block.block.claro_local_tasks.
[notice] Synchronized configuration: delete block.block.claro_page_title.
[notice] Finalizing configuration synchronization.
[success] The configuration was imported successfully.
Proposed resolution
block_theme_initialize should not run, so that there is no need to delete these created blocks.
Comment | File | Size | Author |
---|---|---|---|
#6 | block_theme_initialize_no_create-3182716-6.patch | 658 bytes | Primsi |
#5 | block_theme_initialize_no_create-3182716-5.patch | 657 bytes | Primsi |
Comments
Comment #5
Primsi CreditAttribution: Primsi at MD Systems GmbH for MD Systems GmbH commentedDiscussed this with Berdir. Here is an initial patch.
Comment #6
Primsi CreditAttribution: Primsi at MD Systems GmbH for MD Systems GmbH commentedComment #7
smustgrave CreditAttribution: smustgrave at Mobomo commentedSeems like a perfect test case scenario.
Comment #8
smustgrave CreditAttribution: smustgrave at Mobomo commentedActually not sure if this is the best approach? With or without the patch the theme being installed will not get the default blocks you would get when enabling a theme the normal way.
Comment #9
BerdirI don't know what you mean. That's the whole point of this issue? Config import must not never have any side effects, it should only import exactly the configuration that you prepared and nothing. You have to install as usual the theme at some point, then it initializes the blocks, then you customize them, and then you export and import the final state.
Comment #10
smustgrave CreditAttribution: smustgrave at Mobomo commentedAh just doesn’t seem like a valid workflow. But if that’s the case I don’t think there’s any test case to add. Unless there is way to see output from drush.
Comment #11
smustgrave CreditAttribution: smustgrave at Mobomo commentedBased on #9 the patch in #6 does what is expected.
I manually edited my core.extension.yml file by adding bartik to it
Did a drush cim
Verified I did not see any blocks created.
Since with or without the patch the blocks aren't there after configuration is imported I'm not sure there is a test for this. Unless we can see the output of drush cim.
Comment #12
BerdirOne way to test for it would be to have a hook_block_insert() implementation in a test module and registering what kind of blocks get deleted during config import, but yes, I'm not sure it's worth that.
That, or we make a kernel test where we directly call that function and simulate that config sync is on, that might be easier?
Comment #13
smustgrave CreditAttribution: smustgrave at Mobomo commentedI vote for the 2nd option.
Comment #14
smustgrave CreditAttribution: smustgrave at Mobomo commentedActually not 100% how to simulate the act of importing partially. Any good examples?
Comment #17
rcodina CreditAttribution: rcodina at Seidor commentedI ended up here because I'm doing a migration from core 9.5.11 to 10.1.5. On 9.5.11 we had Adminimal theme as admin theme and now we are enabling and configuring the Claro theme. The enabled Claro blocks are all set in yml config files (default blocks, no custom modifications). The problem is that when I import the configuration using customer's environment database the following error shows up:
Using patch on #6 it avoids the import error. However, the blocks we have set in yml files doesn't get imported. Moreover, If do a "drush cex", it deletes the claro blocks I had defined on those files:
Why they get deleted? Why they don't get imported?
Once the configuration import using customer's environment database is done, If I uninstall claro and I reenable it using the UI, all the default blocks are recreated. Then, If I export the configuration and I compare it with previous claro blocks yml file, the only change is in the uuid property. So it seems that for deploying on customer environment, we would need to uninstall and install again the Claro theme.