fix: properly resolve myep urls per site by overriding in typoscript
This commit is contained in:
@@ -5,35 +5,51 @@ namespace EP\EpProducts\Service;
|
|||||||
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
|
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
|
||||||
use TYPO3\CMS\Core\SingletonInterface;
|
use TYPO3\CMS\Core\SingletonInterface;
|
||||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||||
|
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
|
||||||
|
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
|
||||||
|
|
||||||
class MyEpUrlResolverService implements SingletonInterface
|
class MyEpUrlResolverService implements SingletonInterface
|
||||||
{
|
{
|
||||||
/** @var string */
|
|
||||||
private $productionUrl;
|
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
private $stagingUrl;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$config = GeneralUtility::makeInstance(ExtensionConfiguration::class);
|
|
||||||
$this->productionUrl = (string) $config->get('ep_products', 'myEpUrl');
|
|
||||||
$this->stagingUrl = (string) $config->get('ep_products', 'myEpStagingUrl');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the staging URL when the `ep_myep_staging` cookie is set and a staging URL
|
* Returns the staging URL when the `ep_myep_staging` cookie is set and a staging URL
|
||||||
* is configured. Falls back to the production URL in all other cases.
|
* is configured. Falls back to the production URL in all other cases.
|
||||||
*
|
|
||||||
* Both URLs are read from the extension configuration (Extension Manager),
|
|
||||||
* bypassing TypoScript to avoid constant-override collisions.
|
|
||||||
*/
|
*/
|
||||||
public function resolve(): string
|
public function resolve(): string
|
||||||
{
|
{
|
||||||
if ('' !== $this->stagingUrl && !empty($_COOKIE['ep_myep_staging'])) {
|
$config = GeneralUtility::makeInstance(ExtensionConfiguration::class);
|
||||||
return $this->stagingUrl;
|
$settings = $this->getTypoScriptSettings();
|
||||||
|
$productionUrl = $this->resolveUrlSetting(
|
||||||
|
$settings,
|
||||||
|
'myEpUrl',
|
||||||
|
(string) $config->get('ep_products', 'myEpUrl')
|
||||||
|
);
|
||||||
|
$stagingUrl = $this->resolveUrlSetting(
|
||||||
|
$settings,
|
||||||
|
'myEpStagingUrl',
|
||||||
|
(string) $config->get('ep_products', 'myEpStagingUrl')
|
||||||
|
);
|
||||||
|
|
||||||
|
if ('' !== $stagingUrl && !empty($_COOKIE['ep_myep_staging'])) {
|
||||||
|
return $stagingUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->productionUrl;
|
return $productionUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getTypoScriptSettings(): array
|
||||||
|
{
|
||||||
|
$configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
|
||||||
|
$settings = GeneralUtility::removeDotsFromTS(
|
||||||
|
$configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT)
|
||||||
|
);
|
||||||
|
|
||||||
|
return $settings['plugin']['tx_epproducts']['settings'] ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function resolveUrlSetting(array $settings, string $key, string $fallback): string
|
||||||
|
{
|
||||||
|
$value = trim((string) ($settings[$key] ?? ''));
|
||||||
|
|
||||||
|
return $value !== '' ? $value : $fallback;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,10 @@ plugin.tx_epproducts {
|
|||||||
searchLogIgnoreIps =
|
searchLogIgnoreIps =
|
||||||
# cat=epproducts/140/120; type=string; label=Concept UIDs to trigger inquiry form on product detail page (CSV)
|
# cat=epproducts/140/120; type=string; label=Concept UIDs to trigger inquiry form on product detail page (CSV)
|
||||||
groupInquiryFormConceptUids =
|
groupInquiryFormConceptUids =
|
||||||
|
# cat=epproducts/140/130; type=string; label=Per-site MyE&P booking URL override
|
||||||
|
myEpUrl =
|
||||||
|
# cat=epproducts/140/140; type=string; label=Per-site MyE&P staging booking URL override
|
||||||
|
myEpStagingUrl =
|
||||||
}
|
}
|
||||||
persistence {
|
persistence {
|
||||||
# cat=epproducts/100/100; type=string; label=Default storage PID
|
# cat=epproducts/100/100; type=string; label=Default storage PID
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ plugin.tx_epproducts {
|
|||||||
noInfoConceptUids = {$plugin.tx_epproducts.settings.noInfoConceptUids}
|
noInfoConceptUids = {$plugin.tx_epproducts.settings.noInfoConceptUids}
|
||||||
priceTableRoomTypes = {$plugin.tx_epproducts.settings.priceTableRoomTypes}
|
priceTableRoomTypes = {$plugin.tx_epproducts.settings.priceTableRoomTypes}
|
||||||
searchLogIgnoreIps = {$plugin.tx_epproducts.settings.searchLogIgnoreIps}
|
searchLogIgnoreIps = {$plugin.tx_epproducts.settings.searchLogIgnoreIps}
|
||||||
|
myEpUrl = {$plugin.tx_epproducts.settings.myEpUrl}
|
||||||
|
myEpStagingUrl = {$plugin.tx_epproducts.settings.myEpStagingUrl}
|
||||||
groupsPageUid = {$plugin.tx_eptheme.settings.groupsPageUid}
|
groupsPageUid = {$plugin.tx_eptheme.settings.groupsPageUid}
|
||||||
travelInfoPageUid = {$plugin.tx_eptheme.settings.travelInfoPageUid}
|
travelInfoPageUid = {$plugin.tx_eptheme.settings.travelInfoPageUid}
|
||||||
groupsContactFormPageUid = {$plugin.tx_eptheme.settings.groupsContactFormPageUid}
|
groupsContactFormPageUid = {$plugin.tx_eptheme.settings.groupsContactFormPageUid}
|
||||||
|
|||||||
Reference in New Issue
Block a user