-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Installing default blocks #212
base: 2.x
Are you sure you want to change the base?
Conversation
There's a few bits of configuration that I want to add to this, but it works. Please take a look and tell me what you think! I'd recommend starting with the tests: They include a module called localgov_core_default_blocks_test which does nothing but provide a custom block plugin and some configuration to place it using the new mechanism. |
@andybroomfield I'd like it if people didn't have to do both the existing method of using optional config and the new one. We could support your use case of install into olivero (or another theme with different regions) by using your idea about an array of themes rather than a single value. So if you wanted a block in content_below on olivero, or content_bottom on a localgov theme, you'l list both, and it'd check the regions in order and install into all the localgov themes, plus olivero if it's set as the active theme. For alert banner, I'd suggest that you add the yml files for this new mechanism and remove the existing config. There's currently only config there for base and scarfolk, and I have a strong suspicion that anyone who's using one of those themes will have localgov_core installed anyway. Anyone who's got a subtheme of base probably won't get the blocks anyway using the current methodology, so nothing's been lost, and at least if they have a subtheme of base and localgov_core installed, they will get them. |
Discussing this today in Merge Tuesday, general enthusiasm for the approach. @Adnan-cds also mentioned the possibility of listing multiple potential regions a block might want to be in. It'd be good to test this more widely and get this in soon. |
…contain characters like : which aren't allowed in config IDs.
@rupertj I'm testing this, finally! |
I've tested the functionality, and confirmed that it works. block config placed in /config/localgov does get installed (as long as it's extension is .yml not .yaml 😄 ) Could do with another review of the code if possible, but I've stepped through it with xdebug and it all makes sense to me. @andybroomfield you happy with the code? |
…Block\BlockPluginTrait::getMachineNameSuggestion().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may have found an issue with this. To test I moved the base block config for LGD services from the optional
dir into a localgov
dir, removed the theme settings from the YAML and deleted the block config for the scarfolk theme.
Site installs fail with the error The theme core does not exist.
It looks like when the install hook is running neither the LGD base or Scarfolk themes are enabled and the DeffaultBlockInstaller::targetThemes() method is returning 'core' as a theme.
Am I missing something in the testing here?
I think you're concern @stephen-cox is also fixed now? |
Unfortunately, I've found another couple of problems with this. The block installer doesn't check dependencies so it can try to install blocks before the code defining them has been enabled, which displays a warning. This is not a serious issue though, it just means we have to be sure all dependencies are in place in a module that contains the block config. More of a problem is how Drupal handles enabling blocks in a theme before the theme is installed. It looks like blocks are added to the first theme region and disabled. So the blocks don't show without some manually intervention. For a site install it would be better to have the block installer triggered after the themes are installed, but that's going to mean overhauling how this is triggered. It would be nice if there was a hook for when site installs are finished, but this doesn't look to exist (https://www.drupal.org/project/drupal/issues/2924549). |
Ah, that's annoying. Thanks for the further testing though. I could add an install step to the end of the localgov profile to set up the blocks? |
Assuming this is going to be used as with site installs (which I assume it will be if we include Publications) then I think this sounds sensible. Maybe only work for themes that are installed (ignoring core) and then provide a way for projects and themes to rerun the block installer - or something like that. |
Adds a feature that installs default blocks for other LGD modules.
Implements the ideas discussed in #211.