From 7853b941498c958149663420a6c58df7518fe5b5 Mon Sep 17 00:00:00 2001 From: Sven Berg Ryen <svenryen@gmail.com> Date: Thu, 30 Jan 2025 09:21:31 +0100 Subject: [PATCH] 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. --- src/Config/ConfigUibOverride.php | 25 ++++++++++++++++++++++++- uib_common_ui.services.yml | 1 + 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Config/ConfigUibOverride.php b/src/Config/ConfigUibOverride.php index dcf909a..1691174 100644 --- a/src/Config/ConfigUibOverride.php +++ b/src/Config/ConfigUibOverride.php @@ -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 ?? []; } diff --git a/uib_common_ui.services.yml b/uib_common_ui.services.yml index e2a7a6e..f599c40 100644 --- a/uib_common_ui.services.yml +++ b/uib_common_ui.services.yml @@ -1,5 +1,6 @@ services: uib_common_ui.overrider: class: Drupal\uib_common_ui\Config\ConfigUibOverride + arguments: ['@module_handler'] tags: - {name: config.factory.override, priority: 5} -- GitLab