Skip to content

Commit

Permalink
Merge pull request #701 from City-of-Helsinki/UHF-X_config_override_d…
Browse files Browse the repository at this point in the history
…ocumentation

Update development.md
  • Loading branch information
khalima authored Feb 28, 2024
2 parents 372c946 + 342ae3c commit 41e6be8
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions documentation/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,28 @@ The update hook above will re-import all configuration from `helfi_media` module

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

##### In this example we would want to override Text paragraph label with a configuration found in my_module.

To trigger the `hook_rewrite_config_update`, implement the hook to your `my_module.module`:
```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');
function my_module_rewrite_config_update(string $module, Drupal\config_rewrite\ConfigRewriterInterface $configRewriter): void {
if ($module === 'helfi_paragraphs_text') {
// Rewrite helfi_paragraphs_text configuration.
$configRewriter->rewriteModuleConfig('my_module');
}
}
```
This hook will trigger when `\Drupal::service('helfi_platform_config.config_update_helper')->update('helfi_paragraphs_text');` is run and it will search for configurations in `my_module/config/rewrite/` folder.

To override configurations for your Drupal instance, follow the instructions found in [Rewrite module project page](https://www.drupal.org/project/config_rewrite).

In our example, the label change would be implemented in a configuration file `/public/modules/custom/my_module/config/rewrite/paragraphs.paragraphs_type.text.yml`:
```yml
label: Text (override)
```
The label change for the Finnish translation would be implemented in a configuration file `/public/modules/custom/my_module/config/rewrite/language/fi/paragraphs.paragraphs_type.text.yml`
```yml
label: Teksti (ylikirjoitettu)
```


0 comments on commit 41e6be8

Please sign in to comment.