Skip to content

Commit

Permalink
Merge pull request #699 from City-of-Helsinki/UHF-9491
Browse files Browse the repository at this point in the history
UHF-9491: Allow rewriting config on update
  • Loading branch information
hyrsky authored Feb 27, 2024
2 parents e2f47f1 + c04319f commit 372c946
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
19 changes: 16 additions & 3 deletions documentation/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ function helfi_sote_helfi_paragraph_types() : array {
## Blocks
To install blocks in your module, you should define them in the module's `.module` file and use the `BlockInstaller` service to handle block installations.

Usually, block configurations are installed using YAML files located in `./config/optional/block.block.block_name.yml`, similar to how it is done in install profiles. However, in our case, using this approach would result in unnecessary configuration reverts when the `helfi_platform_config.config_update_helper` service is used. With `BlockInstaller` service, you can install the block configurations for multiple themes without having the unnecessary configuration reverts during module updates and without duplicated configuration files under config folders.
Usually, block configurations are installed using YAML files located in `./config/optional/block.block.block_name.yml`, similar to how it is done in install profiles. However, in our case, using this approach would result in unnecessary configuration reverts when the `helfi_platform_config.config_update_helper` service is used. With `BlockInstaller` service, you can install the block configurations for multiple themes without having the unnecessary configuration reverts during module updates and without duplicated configuration files under config folders.

Define the block as follows:
```
```php
/**
* Gets the block configurations.
*
Expand Down Expand Up @@ -158,7 +158,7 @@ function my_example_get_block_configurations(string $theme) : array {
```

And install the blocks in the modules install/update hooks:
```
```php
/**
* Implements hook_install().
*/
Expand Down Expand Up @@ -224,3 +224,16 @@ function helfi_media_update_9001() : void {
}
```
The update hook above will re-import all configuration from `helfi_media` module's `config/install` and `config/rewrite` folders and run necessary post-update hooks.

#### Rewrite configuration

The `helfi_platform_config.config_update_helper` invokes `hook_rewrite_config_update`, which allows custom modules to react to config re-importing.

```php
function helfi_kasko_content_rewrite_config_update(string $module, Drupal\config_rewrite\ConfigRewriterInterface $configRewriter): void {
if ($module === 'helfi_tpr_config') {
// Rewrite helfi_tpr_config configuration.
$configRewriter->rewriteModuleConfig('helfi_kasko_content');
}
}
```
6 changes: 6 additions & 0 deletions src/ConfigUpdate/ConfigUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public function update(string $module) : void {
}
}

// Allow modules to rewrite config based on updated modules.
$this->moduleHandler->invokeAll('rewrite_config_update', [
$module,
$this->configRewriter,
]);

// Update all paragraph field handlers.
helfi_platform_config_update_paragraph_target_types();
}
Expand Down

0 comments on commit 372c946

Please sign in to comment.