diff --git a/library/Terminal42/ChangeLanguage/EventListener/InsertTagsListener.php b/library/Terminal42/ChangeLanguage/EventListener/InsertTagsListener.php index a94556b..3ffafb8 100644 --- a/library/Terminal42/ChangeLanguage/EventListener/InsertTagsListener.php +++ b/library/Terminal42/ChangeLanguage/EventListener/InsertTagsListener.php @@ -12,6 +12,7 @@ namespace Terminal42\ChangeLanguage\EventListener; use Contao\Controller; +use Contao\PageModel; use Terminal42\ChangeLanguage\PageFinder; class InsertTagsListener @@ -33,7 +34,12 @@ public function onReplaceInsertTags($insertTag) try { $pageFinder = new PageFinder(); - $currentPage = \PageModel::findByIdOrAlias($parts[1]); + $currentPage = PageModel::findByIdOrAlias($parts[1]); + + if (null === $currentPage) { + return ''; + } + $targetPage = $pageFinder->findAssociatedForLanguage($currentPage, $parts[2]); } catch (\RuntimeException $e) { // parent page of current page not found or not published