Get the details of a page including inherited parameters
public loadDetails ( ) : |
||
return | The page model |
/** * Alter the "domain" key * * @return static The page model */ public function loadDetails() { parent::loadDetails(); // Return the current host if in dns list or the full dns list to have a domain restriction at all $this->domain = in_array(\Environment::get('host'), trimsplit(',', $this->domain)) ? \Environment::get('host') : $this->domain; return $this; }
/** * Generate the page title with ##title## as placeholder for dynamic title * * @param PageModel $pageModel * * @return string */ protected function generatePageTitle(PageModel $pageModel) { $pageModel->loadDetails(); $layoutModel = LayoutModel::findByPk($pageModel->layout); if ($layoutModel === null) { return '##title##'; } $title = $layoutModel->titleTag ?: '{{page::pageTitle}} - {{page::rootPageTitle}}'; $title = str_replace('{{page::pageTitle}}', '##title##', $title); // Fake the global page object $GLOBALS['objPage'] = $pageModel; // Replace the insert tags $title = Controller::replaceInsertTags($title, false); // Remove the faked global page object unset($GLOBALS['objPage']); return $title; }
/** * Get the details of a page including inherited parameters * * @param mixed $intId A page ID or a Model object * * @return \PageModel The page model or null * * @deprecated Deprecated since Contao 4.0, to be removed in Contao 5.0. * Use PageModel::findWithDetails() or PageModel->loadDetails() instead. */ public static function getPageDetails($intId) { trigger_error('Using Controller::getPageDetails() has been deprecated and will no longer work in Contao 5.0. Use PageModel::findWithDetails() or PageModel->loadDetails() instead.', E_USER_DEPRECATED); if ($intId instanceof \PageModel) { return $intId->loadDetails(); } elseif ($intId instanceof \Model\Collection) { /** @var \PageModel $objPage */ $objPage = $intId->current(); return $objPage->loadDetails(); } elseif (is_object($intId)) { $strKey = __METHOD__ . '-' . $intId->id; // Try to load from cache if (\Cache::has($strKey)) { return \Cache::get($strKey); } // Create a model from the database result $objPage = new \PageModel(); $objPage->setRow($intId->row()); $objPage->loadDetails(); \Cache::set($strKey, $objPage); return $objPage; } else { // Invalid ID if (!strlen($intId) || $intId < 1) { return null; } $strKey = __METHOD__ . '-' . $intId; // Try to load from cache if (\Cache::has($strKey)) { return \Cache::get($strKey); } $objPage = \PageModel::findWithDetails($intId); \Cache::set($strKey, $objPage); return $objPage; } }
/** * Add the file meta information to the request * * @param string $strUuid * @param string $strPtable * @param integer $intPid */ public static function addFileMetaInformationToRequest($strUuid, $strPtable, $intPid) { $objFile = \FilesModel::findByUuid($strUuid); if ($objFile === null) { return; } $arrMeta = \StringUtil::deserialize($objFile->meta); if (empty($arrMeta)) { return; } $objPage = null; $db = \Database::getInstance(); if ($strPtable == 'tl_article') { $objPage = $db->prepare("SELECT * FROM tl_page WHERE id=(SELECT pid FROM tl_article WHERE id=?)")->execute($intPid); } else { // HOOK: support custom modules if (isset($GLOBALS['TL_HOOKS']['addFileMetaInformationToRequest']) && is_array($GLOBALS['TL_HOOKS']['addFileMetaInformationToRequest'])) { foreach ($GLOBALS['TL_HOOKS']['addFileMetaInformationToRequest'] as $callback) { if (($val = \System::importStatic($callback[0])->{$callback[1]}($strPtable, $intPid)) !== false) { $objPage = $val; } } } } if ($objPage === null || $objPage->numRows < 1) { return; } $objModel = new \PageModel(); $objModel->setRow($objPage->row()); $objModel->loadDetails(); // Convert the language to a locale (see #5678) $strLanguage = str_replace('-', '_', $objModel->rootLanguage); if (isset($arrMeta[$strLanguage])) { if (\Input::post('alt') == '' && !empty($arrMeta[$strLanguage]['title'])) { \Input::setPost('alt', $arrMeta[$strLanguage]['title']); } if (\Input::post('caption') == '' && !empty($arrMeta[$strLanguage]['caption'])) { \Input::setPost('caption', $arrMeta[$strLanguage]['caption']); } } }
/** * @param PageModel $page * * @return PageModel|null */ public function findAssociatedInMaster(PageModel $page) { $page->loadDetails(); $masterRoot = $this->findMasterRootForPage($page); if ($masterRoot->id === $page->rootId) { return null; } $associated = $this->findAssociatedForPage($page); foreach ($associated as $model) { $model->loadDetails(); if ($model->rootId === $masterRoot->id) { return $model; } } return null; }
/** * Returns HTML markup for the global operation. * * @param PageModel $page * @param array $languages * * @return string */ private function onSwitchButtonCallback(PageModel $page, array $languages) { $page->loadDetails(); $list = ''; $markup = <<<'HTML' <div class="header_switchLanguage"> <svg viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M782 1078q-1 3-12.5-.5t-31.5-11.5l-20-9q-44-20-87-49-7-5-41-31.5t-38-28.5q-67 103-134 181-81 95-105 110-4 2-19.5 4t-18.5 0q6-4 82-92 21-24 85.5-115t78.5-118q17-30 51-98.5t36-77.5q-8-1-110 33-8 2-27.5 7.5t-34.5 9.5-17 5q-2 2-2 10.5t-1 9.5q-5 10-31 15-23 7-47 0-18-4-28-21-4-6-5-23 6-2 24.5-5t29.5-6q58-16 105-32 100-35 102-35 10-2 43-19.5t44-21.5q9-3 21.5-8t14.5-5.5 6 .5q2 12-1 33 0 2-12.5 27t-26.5 53.5-17 33.5q-25 50-77 131l64 28q12 6 74.5 32t67.5 28q4 1 10.5 25.5t4.5 30.5zm-205-486q3 15-4 28-12 23-50 38-30 12-60 12-26-3-49-26-14-15-18-41l1-3q3 3 19.5 5t26.5 0 58-16q36-12 55-14 17 0 21 17zm698 129l63 227-139-42zm-1108 800l694-232v-1032l-694 233v1031zm1241-317l102 31-181-657-100-31-216 536 102 31 45-110 211 65zm-503-962l573 184v-380zm311 1323l158 13-54 160-40-66q-130 83-276 108-58 12-91 12h-84q-79 0-199.5-39t-183.5-85q-8-7-8-16 0-8 5-13.5t13-5.5q4 0 18 7.5t30.5 16.5 20.5 11q73 37 159.5 61.5t157.5 24.5q95 0 167-14.5t157-50.5q15-7 30.5-15.5t34-19 28.5-16.5zm448-1079v1079l-774-246q-14 6-375 127.5t-368 121.5q-13 0-18-13 0-1-1-3v-1078q3-9 4-10 5-6 20-11 106-35 149-50v-384l558 198q2 0 160.5-55t316-108.5 161.5-53.5q20 0 20 21v418z"/></svg> <strong>%s:</strong> <span>%s <ul> <li><strong>%s:</strong></li> %s </ul> </span> </div> HTML; foreach ($languages as $id => $language) { $list .= sprintf('<li><a href="%s" title="%s">%s</a></li>', Backend::addToUrl('&switchLanguage=' . $id), sprintf($GLOBALS['TL_LANG']['MSC']['switchLanguageTo'][1], $language), $language); } return sprintf($markup, $GLOBALS['TL_LANG']['MSC']['switchLanguage'], $this->getLanguageLabel($page->language), $GLOBALS['TL_LANG']['MSC']['switchLanguageTo'][0], $list); }