We encounter the same issue, but in general.
Our setup is:
- Root
| - Global Content (no domain)
| | - Pages
| | - News
| | - Projects
| - Website 1 (domain 1)
| | - Mount Point to Global Content
| - Website 2 (domain 2)
| | - Mount Point to Global Content
News and Projects are also normal TYPO3 pages.
If you link to a page with configured MP_mapRootPoints, the domain is also changed.
That will change the context of the website which, in our opinion, is not intended.
We use mount points to mount whole page trees into another site.
We've fixed it at the moment with the following code:
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['linkData-PostProc'][$_EXTKEY]
= '&WebVision\WvCore\Hooks\UrlGenerationHandling->linkData';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['typoLink_PostProc'][$_EXTKEY]
= '&WebVision\WvCore\Hooks\UrlGenerationHandling->typoLinkPostProc';
<?php
namespace WebVision\WvCore\Hooks;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\TypoScript\TemplateService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
/**
* Contains hooks to manipulate generation of frontend urls.
*
* Will keep current domain for urls containing MP vars.
* That are all urls pointing to a page via mount point where we want to keep
* context of current website. Therefore we keep the current domain.
*
* @author Daniel Siepmann <d.siepmann@web-vision.de>
*/
class UrlGenerationHandling
{
/**
* Domain used in generated link.
*
* Used for later replacement.
*
* @var string
*/
protected $domainInLink = '';
/**
* Defined whether domain needs processing.
*
* @var bool
*/
protected $processDomain = false;
/**
* Hook called with all arguments contained in generated url.
*
* Used to check whether we have to manipulate generated url afterwards.
*
* @param array $params
* @param TemplateService $instance
*
* @return void
*/
public function linkData(array &$params, TemplateService $instance)
{
$this->processDomain = false;
// check if mp is set, if not, exit
if (strpos($params['LD']['linkVars'], 'MP') === false) {
return;
}
$this->processDomain = true;
$this->domainInLink = $params['args']['targetDomain'];
}
/**
* Hook called with generated url.
*
* Used to exchange domain if necessary.
*
* @param array $params
* @param ContentObjectRenderer $instance
*
* @return void
*/
public function typoLinkPostProc(array &$params, ContentObjectRenderer $instance)
{
if (! $this->processDomain) {
return;
}
$currentDomain = (string) GeneralUtility::getIndpEnv('HTTP_HOST');
// Replace TYPO3 generated domain by current domain for link.
$params['finalTag'] = str_replace($this->domainInLink, $currentDomain, $params['finalTag']);
$params['finalTagParts'] = str_replace($this->domainInLink, $currentDomain, $params['finalTagParts']['url']);
$instance->lastTypoLinkUrl = str_replace($this->domainInLink, $currentDomain, $instance->lastTypoLinkUrl);
}
}