Skip to content

Commit

Permalink
Revert some changes now that the debug mode does not require the /pre…
Browse files Browse the repository at this point in the history
…view.php fragment anymore
  • Loading branch information
leofeyer committed Sep 10, 2019
1 parent 6ddce57 commit ac737b4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 46 deletions.
19 changes: 0 additions & 19 deletions src/Resources/contao/controllers/BackendIndex.php
Expand Up @@ -15,7 +15,6 @@
use Scheb\TwoFactorBundle\Security\Authentication\Token\TwoFactorToken;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Router;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;

Expand Down Expand Up @@ -113,27 +112,9 @@ public function run()
$objTemplate->jsDisabled = $GLOBALS['TL_LANG']['MSC']['jsDisabled'];
$objTemplate->targetPath = StringUtil::specialchars($router->generate('contao_backend', array(), Router::ABSOLUTE_URL) . $queryString);
$objTemplate->failurePath = StringUtil::specialchars($router->generate('contao_backend_login', $arrParams, Router::ABSOLUTE_URL));
$objTemplate->frontendUrl = $this->getFrontendUrl($router);

return $objTemplate->getResponse();
}

/**
* Generate the front end URL without the preview script
*/
private function getFrontendUrl(RouterInterface $router)
{
$origContext = $router->getContext();

$context = clone $origContext;
$context->setBaseUrl('');

$router->setContext($context);
$url = $router->generate('contao_root', array(), Router::ABSOLUTE_URL);
$router->setContext($origContext);

return $url;
}
}

class_alias(BackendIndex::class, 'BackendIndex');
21 changes: 2 additions & 19 deletions src/Resources/contao/library/Contao/Controller.php
Expand Up @@ -1093,27 +1093,10 @@ public static function redirect($strLocation, $intStatus=303)
protected static function replaceOldBePaths($strContext)
{
$router = System::getContainer()->get('router');
$previewScript = System::getContainer()->getParameter('contao.preview_script');

$generate = static function ($route) use ($router, $previewScript)
$generate = static function ($route) use ($router)
{
if ($route == 'contao_backend_preview')
{
$origContext = $router->getContext();

$context = clone $origContext;
$context->setBaseUrl($previewScript);

$router->setContext($context);
$url = $router->generate($route);
$router->setContext($origContext);
}
else
{
$url = $router->generate($route);
}

return substr($url, \strlen(Environment::get('path')) + 1);
return substr($router->generate($route), \strlen(Environment::get('path')) + 1);
};

$arrMapper = array
Expand Down
18 changes: 11 additions & 7 deletions src/Resources/contao/library/Contao/Template.php
Expand Up @@ -347,18 +347,22 @@ public function route($strName, $arrParams=array())
*/
public function previewRoute($strName, $arrParams=array())
{
$objRouter = System::getContainer()->get('router');
$objContext = $objRouter->getContext();
$container = System::getContainer();

$objPreviewContext = clone $objContext;
$objPreviewContext->setBaseUrl('/preview.php');
if (!$previewScript = $container->getParameter('contao.preview_script'))
{
return $this->route($strName, $arrParams);
}

$router = $container->get('router');

$objRouter->setContext($objPreviewContext);
$context = $router->getContext();
$context->setBaseUrl($previewScript);

$strUrl = $objRouter->generate($strName, $arrParams);
$strUrl = $router->generate($strName, $arrParams);
$strUrl = substr($strUrl, \strlen(Environment::get('path')) + 1);

$objRouter->setContext($objContext);
$context->setBaseUrl('');

return ampersand($strUrl);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/templates/backend/be_login.html5
Expand Up @@ -59,7 +59,7 @@
</div>
<div class="submit_container cf">
<button type="submit" name="login" id="login" class="tl_submit"><?= $this->loginButton ?></button>
<a href="<?= $this->frontendUrl ?>" class="footer_preview"><?= $this->feLink ?> ›</a>
<a href="<?= $this->route('contao_root') ?>" class="footer_preview"><?= $this->feLink ?> ›</a>
</div>
</div>
</form>
Expand Down

0 comments on commit ac737b4

Please sign in to comment.