Skip to content

Commit

Permalink
Add legacy routing check to ContaoFramework class
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Apr 8, 2020
1 parent b8616b0 commit ec3969d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
Expand Up @@ -13,6 +13,7 @@
namespace Contao\CoreBundle\EventListener\DataContainer;

use Contao\CoreBundle\DataContainer\PaletteManipulator;
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\CoreBundle\ServiceAnnotation\Callback;
use Contao\DataContainer;
use Symfony\Contracts\Translation\TranslatorInterface;
Expand All @@ -26,9 +27,9 @@ class LegacyRoutingListener implements ServiceAnnotationInterface
private $translator;

/**
* @var bool
* @var ContaoFramework
*/
private $legacyRouting;
private $framework;

/**
* @var bool
Expand All @@ -40,10 +41,10 @@ class LegacyRoutingListener implements ServiceAnnotationInterface
*/
private $urlSuffix;

public function __construct(TranslatorInterface $translator, bool $legacyRouting, bool $prependLocale = false, string $urlSuffix = '.html')
public function __construct(TranslatorInterface $translator, ContaoFramework $framework, bool $prependLocale = false, string $urlSuffix = '.html')
{
$this->translator = $translator;
$this->legacyRouting = $legacyRouting;
$this->framework = $framework;
$this->prependLocale = $prependLocale;
$this->urlSuffix = $urlSuffix;
}
Expand All @@ -53,7 +54,7 @@ public function __construct(TranslatorInterface $translator, bool $legacyRouting
*/
public function disableRoutingFields(): void
{
if (!$this->isLegacyRouting()) {
if (!$this->framework->isLegacyRouting()) {
return;
}

Expand Down Expand Up @@ -83,7 +84,7 @@ public function disableRoutingFields(): void
*/
public function overrideLanguagePrefix($value, DataContainer $dc)
{
if (!$this->isLegacyRouting()) {
if (!$this->framework->isLegacyRouting()) {
return $value;
}

Expand All @@ -95,17 +96,10 @@ public function overrideLanguagePrefix($value, DataContainer $dc)
*/
public function overrideUrlSuffix($value)
{
if (!$this->isLegacyRouting()) {
if (!$this->framework->isLegacyRouting()) {
return $value;
}

return $this->urlSuffix;
}

private function isLegacyRouting(): bool
{
return $this->legacyRouting
|| !empty($GLOBALS['TL_HOOKS']['getPageIdFromUrl'])
|| !empty($GLOBALS['TL_HOOKS']['getRootPageFromUrl']);
}
}
17 changes: 16 additions & 1 deletion core-bundle/src/Framework/ContaoFramework.php
Expand Up @@ -69,6 +69,11 @@ class ContaoFramework implements ContaoFrameworkInterface, ContainerAwareInterfa
*/
private $errorLevel;

/**
* @var bool
*/
private $legacyRouting;

/**
* @var Request
*/
Expand All @@ -89,13 +94,14 @@ class ContaoFramework implements ContaoFrameworkInterface, ContainerAwareInterfa
*/
private $hookListeners = [];

public function __construct(RequestStack $requestStack, ScopeMatcher $scopeMatcher, TokenChecker $tokenChecker, string $rootDir, int $errorLevel)
public function __construct(RequestStack $requestStack, ScopeMatcher $scopeMatcher, TokenChecker $tokenChecker, string $rootDir, int $errorLevel, bool $legacyRouting)
{
$this->requestStack = $requestStack;
$this->scopeMatcher = $scopeMatcher;
$this->tokenChecker = $tokenChecker;
$this->rootDir = $rootDir;
$this->errorLevel = $errorLevel;
$this->legacyRouting = $legacyRouting;
}

public function reset(): void
Expand Down Expand Up @@ -167,6 +173,15 @@ public function getAdapter($class): Adapter
return $this->adapterCache[$class];
}

public function isLegacyRouting()
{
$this->initialize();

return $this->legacyRouting
|| !empty($GLOBALS['TL_HOOKS']['getPageIdFromUrl'])
|| !empty($GLOBALS['TL_HOOKS']['getRootPageFromUrl']);
}

/**
* @deprecated Deprecated since Contao 4.0, to be removed in Contao 5.0
*/
Expand Down
1 change: 1 addition & 0 deletions core-bundle/src/Resources/config/services.yml
Expand Up @@ -256,6 +256,7 @@ services:
- '@contao.security.token_checker'
- '%kernel.project_dir%'
- '%contao.error_level%'
- '%contao.legacy_routing%'
public: true
tags:
- { name: kernel.reset, method: reset }
Expand Down

0 comments on commit ec3969d

Please sign in to comment.