From 99b6e9e3db84461e8ade37ac82bc62725fd65523 Mon Sep 17 00:00:00 2001 From: Andreas Schempp Date: Wed, 30 Nov 2022 12:51:28 +0100 Subject: [PATCH] Use dependency injection where possible --- config/services.yaml | 15 +++- contao/config/config.php | 24 +----- contao/dca/tl_page.php | 6 +- src/EventListener/AbstractTableListener.php | 3 - src/EventListener/CallbackSetupListener.php | 29 ++----- .../MissingLanguageIconListener.php | 23 +++-- .../DataContainer/PageFieldsListener.php | 9 +- .../PageInitializationListener.php | 10 ++- .../DataContainer/PageOperationListener.php | 86 +++++++++---------- src/EventListener/InsertTagsListener.php | 19 ++-- .../Navigation/AbstractNavigationListener.php | 10 ++- .../Navigation/ArticleNavigationListener.php | 16 +++- .../Navigation/CalendarNavigationListener.php | 14 +++ .../Navigation/FaqNavigationListener.php | 14 +++ .../Navigation/NewsNavigationListener.php | 14 +++ src/Navigation/NavigationFactory.php | 3 +- 16 files changed, 180 insertions(+), 115 deletions(-) diff --git a/config/services.yaml b/config/services.yaml index e7d1965..a1a93a8 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -3,6 +3,17 @@ services: autoconfigure: true autowire: true - Terminal42\ChangeLanguage\EventListener\DataContainer\UserLabelsListener: ~ + Terminal42\ChangeLanguage\EventListener\: + resource: ../src/EventListener/* + exclude: ../src/EventListener/{BackendView,DataContainer}/* + public: true - Terminal42\ChangeLanguage\Migration\CustomLanguageTextMigration: ~ + Terminal42\ChangeLanguage\EventListener\DataContainer\MissingLanguageIconListener: ~ + Terminal42\ChangeLanguage\EventListener\DataContainer\PageFieldsListener: ~ + Terminal42\ChangeLanguage\EventListener\DataContainer\PageInitializationListener: ~ + Terminal42\ChangeLanguage\EventListener\DataContainer\PageOperationListener: ~ + + Terminal42\ChangeLanguage\EventListener\CallbackSetupListener: + + Terminal42\ChangeLanguage\Migration\: + resource: ../src/Migration/* diff --git a/contao/config/config.php b/contao/config/config.php index 7cd822b..c08153b 100755 --- a/contao/config/config.php +++ b/contao/config/config.php @@ -1,26 +1,8 @@ 'pageTree', 'eval' => array('fieldType'=>'radio', 'multiple'=>false, 'rootNodes'=>[0], 'tl_class'=>'w50 clr'), 'sql' => "int(10) unsigned NOT NULL default '0'", - 'load_callback' => [['Terminal42\ChangeLanguage\EventListener\DataContainer\PageFieldsListener', 'onLoadLanguageMain']], - 'save_callback' => [['Terminal42\ChangeLanguage\EventListener\DataContainer\PageFieldsListener', 'onSaveLanguageMain']], + //'load_callback' => [['Terminal42\ChangeLanguage\EventListener\DataContainer\PageFieldsListener', 'onLoadLanguageMain']], + //'save_callback' => [['Terminal42\ChangeLanguage\EventListener\DataContainer\PageFieldsListener', 'onSaveLanguageMain']], ); $GLOBALS['TL_DCA']['tl_page']['fields']['languageRoot'] = array @@ -25,7 +25,7 @@ 'label' => &$GLOBALS['TL_LANG']['tl_page']['languageRoot'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => array('Terminal42\ChangeLanguage\EventListener\DataContainer\PageFieldsListener', 'onLanguageRootOptions'), + //'options_callback' => array('Terminal42\ChangeLanguage\EventListener\DataContainer\PageFieldsListener', 'onLanguageRootOptions'), 'eval' => array('includeBlankOption'=>true, 'blankOptionLabel'=>&$GLOBALS['TL_LANG']['tl_page']['languageRoot'][2], 'tl_class'=>'w50'), 'sql' => "int(10) unsigned NOT NULL default '0'" ); diff --git a/src/EventListener/AbstractTableListener.php b/src/EventListener/AbstractTableListener.php index 2bfb2ee..e9bed5b 100644 --- a/src/EventListener/AbstractTableListener.php +++ b/src/EventListener/AbstractTableListener.php @@ -8,9 +8,6 @@ abstract class AbstractTableListener { protected string $table; - /** - * Constructor. - */ public function __construct(string $table) { $this->table = $table; diff --git a/src/EventListener/CallbackSetupListener.php b/src/EventListener/CallbackSetupListener.php index 1715754..f60d1ed 100644 --- a/src/EventListener/CallbackSetupListener.php +++ b/src/EventListener/CallbackSetupListener.php @@ -4,24 +4,23 @@ namespace Terminal42\ChangeLanguage\EventListener; +use Contao\CoreBundle\ServiceAnnotation\Hook; use Terminal42\ChangeLanguage\EventListener\BackendView\ArticleViewListener; use Terminal42\ChangeLanguage\EventListener\BackendView\PageViewListener; use Terminal42\ChangeLanguage\EventListener\BackendView\ParentChildViewListener; use Terminal42\ChangeLanguage\EventListener\DataContainer\ArticleListener; use Terminal42\ChangeLanguage\EventListener\DataContainer\CalendarEventsListener; use Terminal42\ChangeLanguage\EventListener\DataContainer\FaqListener; -use Terminal42\ChangeLanguage\EventListener\DataContainer\MissingLanguageIconListener; use Terminal42\ChangeLanguage\EventListener\DataContainer\NewsListener; -use Terminal42\ChangeLanguage\EventListener\DataContainer\PageInitializationListener; -use Terminal42\ChangeLanguage\EventListener\DataContainer\PageOperationListener; use Terminal42\ChangeLanguage\EventListener\DataContainer\ParentTableListener; +/** + * @Hook("loadDataContainer") + */ class CallbackSetupListener { private static array $listeners = [ 'tl_page' => [ - PageInitializationListener::class, - PageOperationListener::class, PageViewListener::class, ], 'tl_article' => [ @@ -50,28 +49,10 @@ class CallbackSetupListener ], ]; - private MissingLanguageIconListener $labelListener; - - /** - * Constructor. - */ - public function __construct() + public function __invoke(string $table): void { - $this->labelListener = new MissingLanguageIconListener(); - } - - /** - * Callback for loadDataContainer hook. - * - * @param string $table - */ - public function onLoadDataContainer($table): void - { - $this->labelListener->register($table); - if (\array_key_exists($table, self::$listeners)) { foreach (self::$listeners[$table] as $class) { - /** @var AbstractTableListener $listener */ $listener = new $class($table); $listener->register(); } diff --git a/src/EventListener/DataContainer/MissingLanguageIconListener.php b/src/EventListener/DataContainer/MissingLanguageIconListener.php index e4a3e62..a429fa9 100644 --- a/src/EventListener/DataContainer/MissingLanguageIconListener.php +++ b/src/EventListener/DataContainer/MissingLanguageIconListener.php @@ -10,6 +10,7 @@ use Contao\CalendarEventsModel; use Contao\CalendarModel; use Contao\Config; +use Contao\CoreBundle\ServiceAnnotation\Hook; use Contao\Date; use Contao\FaqCategoryModel; use Contao\FaqModel; @@ -18,8 +19,12 @@ use Contao\NewsModel; use Contao\PageModel; use Contao\StringUtil; +use Symfony\Component\Security\Core\Security; use Terminal42\ChangeLanguage\Helper\LabelCallback; +/** + * @Hook("loadDataContainer") + */ class MissingLanguageIconListener { private static array $callbacks = [ @@ -30,12 +35,17 @@ class MissingLanguageIconListener 'tl_faq' => 'onFaqChildRecords', ]; + private Security $security; + + public function __construct(Security $security) + { + $this->security = $security; + } + /** * Override core labels to show missing language information. - * - * @param string $table */ - public function register($table): void + public function __invoke(string $table): void { if (\array_key_exists($table, self::$callbacks)) { LabelCallback::createAndRegister( @@ -71,11 +81,14 @@ private function onPageLabel(array $args, $previousResult = null): string return $this->generateLabelWithWarning($label); } + $user = $this->security->getUser(); + if ( isset($mainPage) && $mainPage instanceof PageModel - && \is_array(BackendUser::getInstance()->pageLanguageLabels) - && \in_array($page->rootId, BackendUser::getInstance()->pageLanguageLabels, false) + && $user instanceof BackendUser + && \is_array($user->pageLanguageLabels) + && \in_array($page->rootId, $user->pageLanguageLabels, false) ) { return sprintf( '%s (%s)', diff --git a/src/EventListener/DataContainer/PageFieldsListener.php b/src/EventListener/DataContainer/PageFieldsListener.php index 9894f7c..9ddde97 100644 --- a/src/EventListener/DataContainer/PageFieldsListener.php +++ b/src/EventListener/DataContainer/PageFieldsListener.php @@ -4,6 +4,7 @@ namespace Terminal42\ChangeLanguage\EventListener\DataContainer; +use Contao\CoreBundle\ServiceAnnotation\Callback; use Contao\Database; use Contao\DataContainer; use Contao\Input; @@ -18,6 +19,8 @@ class PageFieldsListener * @param mixed $value * * @return mixed + * + * @Callback(table="tl_page", target="fields.languageMain.load") */ public function onLoadLanguageMain($value, DataContainer $dc) { @@ -54,9 +57,9 @@ public function onLoadLanguageMain($value, DataContainer $dc) * * @param mixed $value * - * @throws \RuntimeException - * * @return mixed + * + * @Callback(table="tl_page", target="fields.languageMain.save") */ public function onSaveLanguageMain($value, DataContainer $dc) { @@ -91,7 +94,7 @@ public function onSaveLanguageMain($value, DataContainer $dc) /** * Gets list of options for language root selection (linking multiple fallback roots on different domains). * - * @return array + * @Callback(table="tl_page", target="fields.languageRoot.options") */ public function onLanguageRootOptions(DataContainer $dc): array { diff --git a/src/EventListener/DataContainer/PageInitializationListener.php b/src/EventListener/DataContainer/PageInitializationListener.php index 046c63e..3d4e589 100644 --- a/src/EventListener/DataContainer/PageInitializationListener.php +++ b/src/EventListener/DataContainer/PageInitializationListener.php @@ -5,17 +5,25 @@ namespace Terminal42\ChangeLanguage\EventListener\DataContainer; use Contao\CoreBundle\DataContainer\PaletteManipulator; +use Contao\CoreBundle\ServiceAnnotation\Hook; use Contao\DataContainer; use Contao\Input; use Contao\PageModel; +/** + * @Hook("loadDataContainer") + */ class PageInitializationListener { /** * Register our own callbacks. */ - public function register(): void + public function __invoke(string $table): void { + if ('tl_page' !== $table) { + return; + } + $GLOBALS['TL_DCA']['tl_page']['config']['onload_callback'][] = function (DataContainer $dc): void { $this->onLoad($dc); }; diff --git a/src/EventListener/DataContainer/PageOperationListener.php b/src/EventListener/DataContainer/PageOperationListener.php index c218cd4..387e5ba 100644 --- a/src/EventListener/DataContainer/PageOperationListener.php +++ b/src/EventListener/DataContainer/PageOperationListener.php @@ -4,33 +4,49 @@ namespace Terminal42\ChangeLanguage\EventListener\DataContainer; +use Contao\CoreBundle\ServiceAnnotation\Hook; use Contao\Database; use Contao\DataContainer; use Contao\PageModel; +use Doctrine\DBAL\Connection; use Terminal42\ChangeLanguage\PageFinder; +/** + * @Hook("loadDataContainer") + */ class PageOperationListener { - public function register(): void + private Connection $connection; + + public function __construct(Connection $connection) { - $GLOBALS['TL_DCA']['tl_page']['config']['oncopy_callback'][] = $this->selfCallback('onCopy'); - $GLOBALS['TL_DCA']['tl_page']['config']['oncut_callback'][] = $this->selfCallback('onCut'); - $GLOBALS['TL_DCA']['tl_page']['config']['onsubmit_callback'][] = $this->selfCallback('onSubmit'); - $GLOBALS['TL_DCA']['tl_page']['config']['ondelete_callback'][] = $this->selfCallback('onDelete'); - $GLOBALS['TL_DCA']['tl_page']['config']['onundo_callback'][] = $this->selfCallback('onUndo'); + $this->connection = $connection; + } + + public function __invoke(string $table): void + { + if ('tl_page' !== $table) { + return; + } + + $GLOBALS['TL_DCA']['tl_page']['config']['oncopy_callback'][] = fn (...$args) => $this->onCopy(...$args); + $GLOBALS['TL_DCA']['tl_page']['config']['oncut_callback'][] = fn (...$args) => $this->onCut(...$args); + $GLOBALS['TL_DCA']['tl_page']['config']['onsubmit_callback'][] = fn (...$args) => $this->onSubmit(...$args); + $GLOBALS['TL_DCA']['tl_page']['config']['ondelete_callback'][] = fn (...$args) => $this->onDelete(...$args); + $GLOBALS['TL_DCA']['tl_page']['config']['onundo_callback'][] = fn ($table, array $row) => $this->onUndo($row); } /** * Handles submitting a page and resets tl_page.languageMain if necessary. */ - public function onSubmit(DataContainer $dc): void + private function onSubmit(DataContainer $dc): void { if ( 'root' === $dc->activeRecord->type && $dc->activeRecord->fallback && (!$dc->activeRecord->languageRoot || null === PageModel::findByPk($dc->activeRecord->languageRoot)) ) { - $this->resetPageAndChildren($dc->id); + $this->resetPageAndChildren((int) $dc->id); } } @@ -39,38 +55,36 @@ public function onSubmit(DataContainer $dc): void * * @param int $insertId */ - public function onCopy($insertId): void + private function onCopy($insertId): void { - $this->validateLanguageMainForPage($insertId); + $this->validateLanguageMainForPage((int) $insertId); } /** * Handles moving a page and resets tl_page.languageMain if necessary. */ - public function onCut(DataContainer $dc): void + private function onCut(DataContainer $dc): void { - $this->validateLanguageMainForPage($dc->id); + $this->validateLanguageMainForPage((int) $dc->id); } /** * Handles deleting a page and resets tl_page.languageMain if necessary. */ - public function onDelete(DataContainer $dc): void + private function onDelete(DataContainer $dc): void { - $this->resetPageAndChildren($dc->id); + $this->resetPageAndChildren((int) $dc->id); } /** * Handles undo of a deleted page and resets tl_page.languageMain if necessary. - * - * @param string $table */ - public function onUndo($table, array $row): void + private function onUndo(array $row): void { - $this->validateLanguageMainForPage($row['id']); + $this->validateLanguageMainForPage((int) $row['id']); } - private function validateLanguageMainForPage($pageId): void + private function validateLanguageMainForPage(int $pageId): void { $page = PageModel::findWithDetails($pageId); @@ -90,7 +104,7 @@ private function validateLanguageMainForPage($pageId): void // Reset languageMain if another page in the new page tree has the same languageMain if ($duplicates > 0) { - $this->resetPageAndChildren($page->id); + $this->resetPageAndChildren((int) $page->id); return; } @@ -100,43 +114,27 @@ private function validateLanguageMainForPage($pageId): void // Reset languageMain if current tree has no master or if it's the master tree if (null === $masterRoot || $masterRoot->id === $page->rootId) { - $this->resetPageAndChildren($page->id); + $this->resetPageAndChildren((int) $page->id); return; } // Reset languageMain if the current value is not a valid ID of the master tree if (!\in_array($page->languageMain, Database::getInstance()->getChildRecords($masterRoot->id, 'tl_page'), false)) { - Database::getInstance() - ->prepare('UPDATE tl_page SET languageMain=0 WHERE id=?') - ->execute($page->id) - ; + $this->connection->update('tl_page', ['languageMain' => 0], ['id' => $page->id]); } } - /** - * @param int $pageId - */ - private function resetPageAndChildren($pageId): void + private function resetPageAndChildren(int $pageId): void { $resetIds = Database::getInstance()->getChildRecords($pageId, 'tl_page'); $resetIds[] = $pageId; - Database::getInstance()->query( - 'UPDATE tl_page SET languageMain=0 WHERE id IN ('.implode(',', $resetIds).')' - ); - } - - /** - * @param $method - * - * @return \Closure - */ - private function selfCallback($method) - { - return fn () => \call_user_func_array( - [$this, $method], - \func_get_args() + $this->connection->update( + 'tl_page', + ['languageMain' => 0], + ['id' => $resetIds], + ['id' => Connection::PARAM_INT_ARRAY] ); } } diff --git a/src/EventListener/InsertTagsListener.php b/src/EventListener/InsertTagsListener.php index f188870..acb207e 100644 --- a/src/EventListener/InsertTagsListener.php +++ b/src/EventListener/InsertTagsListener.php @@ -4,21 +4,30 @@ namespace Terminal42\ChangeLanguage\EventListener; +use Contao\CoreBundle\InsertTag\InsertTagParser; +use Contao\CoreBundle\ServiceAnnotation\Hook; use Contao\PageModel; use Contao\StringUtil; -use Contao\System; use Terminal42\ChangeLanguage\PageFinder; +/** + * @Hook("replaceInsertTags") + */ class InsertTagsListener { + private InsertTagParser $parser; + + public function __construct(InsertTagParser $parser) + { + $this->parser = $parser; + } + /** * Replaces {{changelanguage_*::*}} insert tag. * - * @param string $insertTag - * * @return string|false */ - public function onReplaceInsertTags($insertTag) + public function __invoke(string $insertTag) { $parts = StringUtil::trimsplit('::', $insertTag); @@ -40,7 +49,7 @@ public function onReplaceInsertTags($insertTag) return ''; } - return System::getContainer()->get('contao.insert_tag.parser')->replace( + return $this->parser->replace( sprintf( '{{%s::%s}}', substr($parts[0], 15), diff --git a/src/EventListener/Navigation/AbstractNavigationListener.php b/src/EventListener/Navigation/AbstractNavigationListener.php index 97b78c6..bbc1268 100644 --- a/src/EventListener/Navigation/AbstractNavigationListener.php +++ b/src/EventListener/Navigation/AbstractNavigationListener.php @@ -4,6 +4,7 @@ namespace Terminal42\ChangeLanguage\EventListener\Navigation; +use Contao\CoreBundle\Security\Authentication\Token\TokenChecker; use Contao\Date; use Contao\Input; use Contao\Model; @@ -11,6 +12,13 @@ abstract class AbstractNavigationListener { + private TokenChecker $tokenChecker; + + public function __construct(TokenChecker $tokenChecker) + { + $this->tokenChecker = $tokenChecker; + } + /** * Find record based on languageMain field and parent master archive. */ @@ -81,7 +89,7 @@ public function onChangelanguageNavigation(ChangelanguageNavigationEvent $event) */ protected function addPublishedConditions(array $columns, string $table, bool $addStartStop = true): array { - if (true !== BE_USER_LOGGED_IN) { + if (!$this->tokenChecker->isPreviewMode()) { $columns[] = "$table.published='1'"; if ($addStartStop) { diff --git a/src/EventListener/Navigation/ArticleNavigationListener.php b/src/EventListener/Navigation/ArticleNavigationListener.php index 5713582..464e837 100644 --- a/src/EventListener/Navigation/ArticleNavigationListener.php +++ b/src/EventListener/Navigation/ArticleNavigationListener.php @@ -5,18 +5,30 @@ namespace Terminal42\ChangeLanguage\EventListener\Navigation; use Contao\ArticleModel; +use Contao\CoreBundle\Security\Authentication\Token\TokenChecker; +use Contao\CoreBundle\ServiceAnnotation\Hook; use Contao\Database; use Contao\Date; use Contao\PageModel; use Terminal42\ChangeLanguage\Event\ChangelanguageNavigationEvent; use Terminal42\ChangeLanguage\PageFinder; +/** + * @Hook("changelanguageNavigation") + */ class ArticleNavigationListener { + private TokenChecker $tokenChecker; + + public function __construct(TokenChecker $tokenChecker) + { + $this->tokenChecker = $tokenChecker; + } + /** * Translate URL parameters for articles. */ - public function onChangelanguageNavigation(ChangelanguageNavigationEvent $event): void + public function __invoke(ChangelanguageNavigationEvent $event): void { // Try to find matching article if ( @@ -93,7 +105,7 @@ private function findTargetArticle(ArticleModel $currentArticle, $targetRootId, */ private function findPublishedArticle(array $columns, array $values = [], array $options = []): ?ArticleModel { - if (true !== BE_USER_LOGGED_IN) { + if (!$this->tokenChecker->isPreviewMode()) { $time = Date::floorToMinute(); $columns[] = "(tl_article.start='' OR tl_article.start<='$time')"; $columns[] = "(tl_article.stop='' OR tl_article.stop>'".($time + 60)."')"; diff --git a/src/EventListener/Navigation/CalendarNavigationListener.php b/src/EventListener/Navigation/CalendarNavigationListener.php index 2e0e720..7d85c50 100644 --- a/src/EventListener/Navigation/CalendarNavigationListener.php +++ b/src/EventListener/Navigation/CalendarNavigationListener.php @@ -4,15 +4,29 @@ namespace Terminal42\ChangeLanguage\EventListener\Navigation; +use Contao\CalendarBundle\ContaoCalendarBundle; use Contao\CalendarEventsModel; use Contao\CalendarModel; +use Contao\CoreBundle\ServiceAnnotation\Hook; use Contao\PageModel; +use Terminal42\ChangeLanguage\Event\ChangelanguageNavigationEvent; /** * Translate URL parameters for calendar events. + * + * @Hook("changelanguageNavigation") */ class CalendarNavigationListener extends AbstractNavigationListener { + public function __invoke(ChangelanguageNavigationEvent $event): void + { + if (!class_exists(ContaoCalendarBundle::class)) { + return; + } + + $this->onChangelanguageNavigation($event); + } + protected function getUrlKey(): string { return 'events'; diff --git a/src/EventListener/Navigation/FaqNavigationListener.php b/src/EventListener/Navigation/FaqNavigationListener.php index b42f85e..b85ed83 100644 --- a/src/EventListener/Navigation/FaqNavigationListener.php +++ b/src/EventListener/Navigation/FaqNavigationListener.php @@ -4,15 +4,29 @@ namespace Terminal42\ChangeLanguage\EventListener\Navigation; +use Contao\CoreBundle\ServiceAnnotation\Hook; +use Contao\FaqBundle\ContaoFaqBundle; use Contao\FaqCategoryModel; use Contao\FaqModel; use Contao\PageModel; +use Terminal42\ChangeLanguage\Event\ChangelanguageNavigationEvent; /** * Translate URL parameters for faq items. + * + * @Hook("changelanguageNavigation") */ class FaqNavigationListener extends AbstractNavigationListener { + public function __invoke(ChangelanguageNavigationEvent $event): void + { + if (!class_exists(ContaoFaqBundle::class)) { + return; + } + + $this->onChangelanguageNavigation($event); + } + protected function getUrlKey(): string { return 'items'; diff --git a/src/EventListener/Navigation/NewsNavigationListener.php b/src/EventListener/Navigation/NewsNavigationListener.php index c152ec3..793eab0 100644 --- a/src/EventListener/Navigation/NewsNavigationListener.php +++ b/src/EventListener/Navigation/NewsNavigationListener.php @@ -4,15 +4,29 @@ namespace Terminal42\ChangeLanguage\EventListener\Navigation; +use Contao\CoreBundle\ServiceAnnotation\Hook; use Contao\NewsArchiveModel; +use Contao\NewsBundle\ContaoNewsBundle; use Contao\NewsModel; use Contao\PageModel; +use Terminal42\ChangeLanguage\Event\ChangelanguageNavigationEvent; /** * Translate URL parameters for news items. + * + * @Hook("changelanguageNavigation") */ class NewsNavigationListener extends AbstractNavigationListener { + public function __invoke(ChangelanguageNavigationEvent $event): void + { + if (!class_exists(ContaoNewsBundle::class)) { + return; + } + + $this->onChangelanguageNavigation($event); + } + protected function getUrlKey(): string { return 'items'; diff --git a/src/Navigation/NavigationFactory.php b/src/Navigation/NavigationFactory.php index d98c5d9..f6a0ad7 100644 --- a/src/Navigation/NavigationFactory.php +++ b/src/Navigation/NavigationFactory.php @@ -5,6 +5,7 @@ namespace Terminal42\ChangeLanguage\Navigation; use Contao\PageModel; +use Contao\System; use Terminal42\ChangeLanguage\Helper\LanguageText; use Terminal42\ChangeLanguage\PageFinder; @@ -121,7 +122,7 @@ private function setTargetPageForNavigationItems(array $navigationItems, array $ */ private function isPagePublished(PageModel $page): bool { - if (\defined('BE_USER_LOGGED_IN') && true === BE_USER_LOGGED_IN) { + if (System::getContainer()->get('contao.security.token_checker')->isPreviewMode()) { return true; }