Skip to content
Snippets Groups Projects
Commit 7853b941 authored by Sven Berg Ryen's avatar Sven Berg Ryen
Browse files

WP3 #1398 Refactor: Inject module handler into ConfigUibOverride.

Added dependency injection for the module handler service to
improve testability and adhere to Drupal's best practices.

Updated logo path resolution to use the dynamically obtained module path.
parent 2ce00efe
No related branches found
No related tags found
1 merge request!7Issue #1398 chore: Introduce config API overrides
Pipeline #272803 passed
......@@ -4,19 +4,42 @@ namespace Drupal\uib_common_ui\Config;
use Drupal\Core\Config\ConfigFactoryOverrideInterface;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
/**
* Provides configuration overrides for the uib_common_ui module.
*/
class ConfigUibOverride implements ConfigFactoryOverrideInterface {
/**
* The module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Constructs a ConfigUibOverride object.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
*/
public function __construct(ModuleHandlerInterface $module_handler) {
$this->moduleHandler = $module_handler;
}
/**
* {@inheritDoc}
*/
public function loadOverrides($names): array {
if (in_array('gin_login.settings', $names, TRUE)) {
$overrides['gin_login.settings']['logo'] = ['path' => 'modules/custom/uib_common_ui/public/image/uib_login_logo.svg'];
// Get the absolute path to the module and append the relative logo path.
$module_path = $this->moduleHandler->getModule('uib_common_ui')->getPath();
$logo_path = $module_path . '/public/image/uib_login_logo.svg';
$overrides['gin_login.settings']['logo'] = ['path' => $logo_path];
}
return $overrides ?? [];
}
......
services:
uib_common_ui.overrider:
class: Drupal\uib_common_ui\Config\ConfigUibOverride
arguments: ['@module_handler']
tags:
- {name: config.factory.override, priority: 5}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment