Problem/Motivation
I am building a recipe to for a basic startup of new projects. I want to use "minimal" profile and then enable claro and other modules. When using recipes, it seems because the installation of the extension happens in a separate step as the configuration, Drupal core will duplicate Stark's (minimal's default theme) blocks. Even by specifying the configs in recipe.yml doesn't help because in the end I have both sets of blocks
Steps to reproduce
- Install Drupal with the minimal profile.
- Apply the core/recipes/core_recommended_admin_theme recipe to the site or a simple recipe that includes that recipe.
- Log in and visit an administrative page. The page has both "tabs" (primary local tasks) and "primary_local_tasks" blocks.
Proposed resolution
Not sure yet, but maybe if I am importing configs provided by the extension, they could be imported during installation?
Note: the code that performs the block duplication runs after any module/theme/profile installation, except during site installation: https://git.drupalcode.org/project/drupal/-/blob/9.5.3/core/modules/bloc...
Comments
Comment #2
franzComment #3
thejimbirch commentedMinimal requires Stark, and imports config: https://git.drupalcode.org/project/drupal/-/tree/9.5.3/core/profiles/min...
Could you require Stark in your recipe, and not import the config?
If that didn't work, do we need a config:remove option in addition to config:import in the recipe.yml?
Comment #4
franz@thejimbirch I'm not sure how requiring stark would help. These block configs are created during site installation. If you look at the link I posted in the description, you'll see that they get duplicated when claro is installed, before its configs are imported. An option to delete configs is certainly useful but in this case it is a workaround. IMO it should be possible to install a theme via recipes with the same outcome as installing manually. Maybe this would require a patch in that code so it doesn't create block copies when installing from recipes? Would certainly be the cleanest way.
Comment #5
sonfdFirst, I just want to add a more verbose version of what you've stated in the project description.
Recipe application installs modules and themes and imports their configuration in two steps, see An example drupal recipe in the distirbutions and recipes initiative docs.
It seems that the block module creates blocks for claro in step 1, via hook_themes_installed(), because the Claro provided blocks are not simple configuration and therefore their configuration is not imported yet). Then the claro blocks get created in step 2, if you've allowed them.
I suspect your recipe looks something like this:
If we don't allow the config entities from Claro to be installed, e.g. by updating your recipe.yml and removing the entry under config, we'll only get one set of blocks, but they'll be the blocks created by the block module in step 1. Though I think we'd really rather get just the set of blocks supplied by the Claro module (if allowed in the recipe.yml), and the block module would never create the set of blocks in step 1 while a recipe is being applied.
IMO, this is the right approach. I think the block module needs to make an exception for when the theme is installed by a recipe. In the code for hook_themes_installed(), you can already see where they've made a similar exception for installation profiles:
Comment #6
thejimbirch commentedAnother person reports this in #3436143: Duplicate blocks appear after standard recipe is applied.
The root core issue is #3105597: Stop copying block configuration from active theme when enabling a new theme.
The issue definitely exists, but you can now use the installer that is in core to install Drupal using a recipe, which bypasses the need for an install profile. This helps the issue if you are starting a new Drupal site, not if you are applying a recipe to an existing site.
php core/scripts/drupal quick-start path/to/recipeComment #7
thejimbirch commentedComment #10
thejimbirch commentedUpdating title, adding credits from duplicate issue.
Comment #11
d70rr3s commentedJust to shed some light on the matter. I'm facing the same issue in this case with GIn theme but, I don't have a
gin: *in my recipe. This is my actual code:Probably blocks by Gin are getting imported even if you explicitly ask for it. Probably a bug somehow?
Comment #12
d70rr3s commentedAh, I see. @sonfd explains it in here, is how the block module behaves when installing a new theme :/
Comment #13
bhuvaneshwar commentedComment #14
prashant.cAdding the related issue.
Comment #15
bhuvaneshwar commentedAgree with #5 in order to omit duplicate blocks while initializing themes we can use:
// Get the list of themes installed and blocks to assign.
$themes = system_list('theme_enabled');
foreach ($themes as $theme => $info) {
// Get the default blocks for the theme.
$blocks = theme_get_default_blocks($theme);
// Filter out duplicates.
$unique_blocks = array_unique($blocks, SORT_REGULAR);
// Assign the unique blocks to their regions.
foreach ($unique_blocks as $block) {
// Assign the block to the region.
block_place_block($block);
}
}
As I'm also facing the same issue in this case with GIn theme but, I don't have a gin: * in my recipe too
Comment #16
bhuvaneshwar commentedComment #17
bsnodgrass commentedmoved to Drupal Core, per https://www.drupal.org/project/distributions_recipes/issues/3513044
Comment #18
mherchelBumping to major.
With Drupal's focus on site templates, this becomes a blocker for that functionality.
Comment #19
mherchelCrap. Forgot to actually change the field!
Comment #20
mradcliffeI stumbled on this and the other issue today working on a recipe.
I updated the steps to reproduce to use an already existing core recipe as an example (core_recommended_admin_theme).
I think that we should do the hook_themes_installed() approach and add a @todo comment linking to #3105597: Stop copying block configuration from active theme when enabling a new theme so that we're not blocked (pun intended).
Comment #21
thejimbirch commentedComment #22
alexpottI think we should do #3182716: block_theme_initialize should not create blocks during config sync which would have the by product of fixing this issue as block_theme_initialize() would no longer trigger during a recipe install.
Comment #23
catchComment #24
thejimbirch commentedRemoving duplicate related issue
Comment #25
thejimbirch commentedRemoving this current issue as a related issue. It was relating to itself.
Comment #26
larowlanComment #27
catch#3182716: block_theme_initialize should not create blocks during config sync is in 11.2 - does that mean this should be closed, or is there more to do on this issue?
Comment #28
thejimbirch commentedYes, that issue fixed the underlying problem.
Comment #29
thejimbirch commentedComment #30
thejimbirch commented