public function onMasterOptions(DataContainer $dc) { if (($jumpTo = PageModel::findByPk($dc->activeRecord->jumpTo)) === null) { return []; } $associated = []; $pageFinder = new PageFinder(); foreach ($pageFinder->findAssociatedForPage($jumpTo, true) as $page) { $associated[] = $page->id; } if (0 === count($associated)) { return []; } $options = []; $result = Database::getInstance()->prepare(' SELECT id, title FROM ' . $this->table . ' WHERE jumpTo IN (' . implode(',', $associated) . ') AND master=0 ORDER BY title ')->execute($dc->activeRecord->language); while ($result->next()) { $options[$result->id] = sprintf($GLOBALS['TL_LANG'][$this->table]['isSlave'], $result->title); } return $options; }
/** * @expectedException \InvalidArgumentException */ public function testThrowsExceptionWhenLanguageDoesNotExist() { $enRoot = $this->createRootPage('en', true); $deRoot = $this->createRootPage('de', false); $en = $this->createPage($enRoot); $dePage = new PageModel(); $dePage->id = $this->createPage($deRoot, $en); $dePage->pid = $deRoot; $dePage->languageMain = $en; $this->pageFinder->findAssociatedForLanguage($dePage, 'fr'); }
/** * @param PageModel $currentPage * * @return NavigationItem[] * * @throws \RuntimeException */ public function findNavigationItems(PageModel $currentPage) { $rootPages = $this->pageFinder->findRootPagesForPage($currentPage, false, false); $navigationItems = $this->createNavigationItemsForRootPages($rootPages); $this->setTargetPageForNavigationItems($navigationItems, $rootPages, $this->pageFinder->findAssociatedForPage($currentPage)); foreach ($navigationItems as $k => $item) { if (!$item->hasTargetPage()) { $item->setTargetPage($this->pageFinder->findAssociatedParentForLanguage($currentPage, $item->getLanguageTag()), false); } } $this->languageText->orderNavigationItems($navigationItems); return array_values($navigationItems); }
public function onLanguageMainOptions(DataContainer $dc) { $pageFinder = new PageFinder(); $current = ArticleModel::findByPk($dc->id); $page = PageModel::findByPk($current->pid); if (null === $page || ($master = $pageFinder->findAssociatedInMaster($page)) === null) { return []; } $options = []; $result = Database::getInstance()->prepare(' SELECT id, title FROM tl_article WHERE pid=? AND id NOT IN ( SELECT languageMain FROM tl_article WHERE id!=? AND pid=? AND languageMain > 0 ) ')->execute($master->id, $current->id, $page->id); while ($result->next()) { $options[$result->id] = sprintf('%s [ID %s]', $result->title, $result->id); } return $options; }
/** * Translate URL parameters for articles. * * @param ChangelanguageNavigationEvent $event */ public function onChangelanguageNavigation(ChangelanguageNavigationEvent $event) { // Try to find matching article if ($event->getNavigationItem()->isCurrentPage() || !$event->getUrlParameterBag()->hasUrlAttribute('articles')) { return; } /** @var PageModel $objPage */ global $objPage; $parameterBag = $event->getUrlParameterBag(); $currentArticle = ArticleModel::findByIdOrAliasAndPid($parameterBag->getUrlAttribute('articles'), $objPage->id); if (null === $currentArticle) { return; } $pageFinder = new PageFinder(); $targetRoot = $event->getNavigationItem()->getRootPage(); $masterRoot = $pageFinder->findMasterRootForPage($targetRoot); $targetArticle = $this->findTargetArticle($currentArticle, $targetRoot->id, $objPage->rootId === $masterRoot->id, null !== $masterRoot && $targetRoot->id === $masterRoot->id); if (null === $targetArticle) { $parameterBag->removeUrlAttribute('articles'); } else { $parameterBag->setUrlAttribute('articles', $targetArticle->alias); } }
public function testKeyEqualsPageId() { $master = $this->createRootPage('foo.com', 'en'); $this->createRootPage('foo.com', 'de', false); $this->createRootPage('bar.com', 'fr', true, $master); $this->createRootPage('bar.com', 'it', false); $pageModel = new PageModel(); $pageModel->id = $master; $pageModel->domain = 'foo.com'; $roots = $this->pageFinder->findRootPagesForPage($pageModel); $this->assertPageCount($roots, 4); foreach ($roots as $id => $page) { $this->assertEquals($page->id, $id); } }
/** * Limits the available pages in page picker to the fallback page tree. * * @param int $pageId */ private function setRootNodesForPage($pageId) { $page = PageModel::findWithDetails($pageId); $root = PageModel::findByPk($page->rootId); if ($root->fallback && (!$root->languageRoot || ($languageRoot = PageModel::findByPk($root->languageRoot)) === null)) { return; } $pageFinder = new PageFinder(); $masterRoot = $pageFinder->findMasterRootForPage($page); if (null !== $masterRoot) { $GLOBALS['TL_DCA']['tl_page']['fields']['languageMain']['eval']['rootNodes'] = Database::getInstance()->prepare('SELECT id FROM tl_page WHERE pid=?')->execute($masterRoot->id)->fetchEach('id'); } }
private function validateLanguageMainForPage($pageId) { $page = PageModel::findWithDetails($pageId); // Moving a root page does not affect language assignments if (null === $page || !$page->languageMain || 'root' === $page->type) { return; } $duplicates = PageModel::countBy(['id IN (' . implode(',', Database::getInstance()->getChildRecords($page->rootId, 'tl_page')) . ')', 'languageMain=?', 'id!=?'], [$page->languageMain, $page->id]); // Reset languageMain if another page in the new page tree has the same languageMain if ($duplicates > 0) { $this->resetPageAndChildren($page->id); return; } $pageFinder = new PageFinder(); $masterRoot = $pageFinder->findMasterRootForPage($page); // 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); return; } // Reset languageMain if the current value is not a valid ID of the master tree if (!in_array($page->id, Database::getInstance()->getChildRecords($masterRoot->id, 'tl_page'), false)) { $this->resetPageAndChildren($page->id); } }