From 698ccd21af94792cf3c2abc0b13054d169ec2e62 Mon Sep 17 00:00:00 2001 From: Timur Tripp Date: Wed, 23 Oct 2024 13:36:45 -0600 Subject: [PATCH] CuBoulder/ucb_site_configuration#69 Prepends site base URL to site-relative search page path --- src/SiteConfiguration.php | 14 +++++++++++++- ucb_site_configuration.info.yml | 2 +- ucb_site_configuration.services.yml | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/SiteConfiguration.php b/src/SiteConfiguration.php index 3d14ef9..b9a6b59 100644 --- a/src/SiteConfiguration.php +++ b/src/SiteConfiguration.php @@ -8,6 +8,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Messenger\MessengerInterface; +use Drupal\Core\Routing\RequestContext; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; @@ -57,6 +58,13 @@ class SiteConfiguration { */ protected $entityTypeRepository; + /** + * The request context. + * + * @var \Drupal\Core\Routing\RequestContext + */ + protected $requestContext; + /** * The current route match. * @@ -86,6 +94,8 @@ class SiteConfiguration { * The entity type manager. * @param \Drupal\Core\Entity\EntityTypeRepositoryInterface $entity_type_repository * The entity type repository. + * @param \Drupal\Core\Routing\RequestContext $request_context + * The request context. * @param \Drupal\Core\Routing\RouteMatchInterface $current_route_match * The current route match. * @param \Drupal\Core\Messenger\MessengerInterface $messenger @@ -98,6 +108,7 @@ public function __construct( TranslationManager $string_translation, EntityTypeManagerInterface $entity_type_manager, EntityTypeRepositoryInterface $entity_type_repository, + RequestContext $request_context, RouteMatchInterface $current_route_match, MessengerInterface $messenger, ) { @@ -107,6 +118,7 @@ public function __construct( $this->stringTranslation = $string_translation; $this->entityTypeManager = $entity_type_manager; $this->entityTypeRepository = $entity_type_repository; + $this->requestContext = $request_context; $this->currentRouteMatch = $current_route_match; $this->messenger = $messenger; } @@ -349,7 +361,7 @@ public function attachSiteInformation(array &$variables) { } $searchUrl = $settings->get('site_search_url'); if ($searchUrl) { - $siteSearchOption['url'] = $searchUrl; + $siteSearchOption['url'] = $this->requestContext->getCompleteBaseUrl() . $searchUrl; } } $variables['site_search'][] = $siteSearchOption; diff --git a/ucb_site_configuration.info.yml b/ucb_site_configuration.info.yml index 15b487e..e4cd075 100644 --- a/ucb_site_configuration.info.yml +++ b/ucb_site_configuration.info.yml @@ -2,7 +2,7 @@ name: CU Boulder Site Configuration description: 'Allows CU Boulder site administrators to configure site-specific settings.' core_version_requirement: ^9 || ^10 type: module -version: '2.8.5' +version: '2.8.6' package: CU Boulder dependencies: - block diff --git a/ucb_site_configuration.services.yml b/ucb_site_configuration.services.yml index 4ef0397..22f08ce 100644 --- a/ucb_site_configuration.services.yml +++ b/ucb_site_configuration.services.yml @@ -8,5 +8,6 @@ services: - '@string_translation' - '@entity_type.manager' - '@entity_type.repository' + - '@router.request_context' - '@current_route_match' - '@messenger'