Skip to content

Commit

Permalink
Consider preview mode for logo uri (see #25)
Browse files Browse the repository at this point in the history
Description
-----------

Fixes #24

- Append the preview script to the logo module URI when activated

Commits
-------

b38c3ae Consider preview mode for logo uri
  • Loading branch information
zoglo authored Jan 22, 2024
2 parents 4c9f0fb + b38c3ae commit e0a7d87
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion contao/modules/ModuleLogo.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ protected function compile(): void
// Create rootHref URL
$strPageUrl = Environment::get('url');

// Contao 4.13 legacy routing fallback + contao 5.1 compatibility
// Append preview script within preview mode
if ($this->isFrontendPreview())
{
$strPageUrl .= $container->getParameter('contao.preview_script') ?? '';
}

// Contao 4.13 legacy routing fallback + contao 5.x compatibility
try {
$prependLocale = $container->getParameter('contao.prepend_locale');
} catch (ParameterNotFoundException $e) {
Expand All @@ -118,6 +124,20 @@ protected function compile(): void
$this->Template->rootHref = $strPageUrl;
$this->Template->title = $strCompanyName;
}

protected function isFrontendPreview(): bool
{
$container = System::getContainer();
$request = $container->get('request_stack')->getCurrentRequest();
$tokenChecker = $container->get('contao.security.token_checker');

if (null === $request || !$request->attributes->get('_preview', false) || !$tokenChecker->canAccessPreview())
{
return false;
}

return true;
}
}

class_alias(ModuleLogo::class, 'ModuleLogo');

0 comments on commit e0a7d87

Please sign in to comment.