-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from City-of-Helsinki/UHF-8103_sitemap_urls
Uhf 8103 sitemap urls
- Loading branch information
Showing
5 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ core_version_requirement: ^8 || ^9 | |
dependencies: | ||
- path_alias | ||
- redirect | ||
- drupal:helfi_api_base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Drupal\helfi_proxy\Config; | ||
|
||
use Drupal\Core\Cache\CacheableMetadata; | ||
use Drupal\Core\Config\ConfigFactoryOverrideInterface; | ||
use Drupal\Core\Config\StorageInterface; | ||
use Drupal\Core\Http\RequestStack; | ||
use Drupal\Core\Language\LanguageManagerInterface; | ||
use Drupal\helfi_proxy\ActiveSitePrefix; | ||
|
||
/** | ||
* Override sitemap path dynamically. | ||
*/ | ||
class SitemapPathOverride implements ConfigFactoryOverrideInterface { | ||
|
||
/** | ||
* Constructs a new instance. | ||
* | ||
* @param \Drupal\helfi_proxy\ActiveSitePrefix $prefix | ||
* The active site prefix service. | ||
* @param \Drupal\Core\Language\LanguageManagerInterface $languageManager | ||
* The language manager. | ||
* @param \Drupal\Core\Http\RequestStack $requestStack | ||
* The request stack. | ||
*/ | ||
public function __construct( | ||
private ActiveSitePrefix $prefix, | ||
private LanguageManagerInterface $languageManager, | ||
private RequestStack $requestStack, | ||
) { | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function loadOverrides($names): array { | ||
$overrides = []; | ||
$url = $this->requestStack->getCurrentRequest()?->getSchemeAndHttpHost(); | ||
|
||
if (!$url) { | ||
return $overrides; | ||
} | ||
|
||
if (in_array('simple_sitemap.settings', $names)) { | ||
$langcode = $this->languageManager->getCurrentLanguage()->getId(); | ||
$prefix = $this->prefix->getPrefix($langcode); | ||
$baseUrl = sprintf('%s/%s/%s', $url, $langcode, $prefix); | ||
$overrides['simple_sitemap.settings']['base_url'] = $baseUrl; | ||
} | ||
|
||
return $overrides; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getCacheSuffix() { | ||
return 'SitemapPathOverride'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getCacheableMetadata($name) { | ||
return new CacheableMetadata(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) { | ||
return NULL; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters