Skip to content

Commit

Permalink
Generate the front end URL in the login screen without the "/preview.…
Browse files Browse the repository at this point in the history
…php" fragment (see #541)
  • Loading branch information
leofeyer committed Jul 3, 2019
1 parent ed729bc commit 9de87dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/Resources/contao/controllers/BackendIndex.php
Expand Up @@ -15,6 +15,7 @@
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 @@ -112,9 +113,27 @@ 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.php" fragment
*/
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');
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->route('contao_root') ?>" class="footer_preview"><?= $this->feLink ?> ›</a>
<a href="<?= $this->frontendUrl ?>" class="footer_preview"><?= $this->feLink ?> ›</a>
</div>
</div>
</form>
Expand Down

0 comments on commit 9de87dc

Please sign in to comment.