Contao\PageModel::loadDetails PHP Метод

loadDetails() публичный Метод

Get the details of a page including inherited parameters
public loadDetails ( ) : PageModel
Результат PageModel The page model
    public function loadDetails()
    {
        // Loaded already
        if ($this->blnDetailsLoaded) {
            return $this;
        }
        // Set some default values
        $this->protected = (bool) $this->protected;
        $this->groups = $this->protected ? \StringUtil::deserialize($this->groups) : false;
        $this->layout = $this->includeLayout ? $this->layout : false;
        $this->mobileLayout = $this->includeLayout ? $this->mobileLayout : false;
        $this->cache = $this->includeCache ? $this->cache : false;
        $this->clientCache = $this->includeCache ? $this->clientCache : false;
        $pid = $this->pid;
        $type = $this->type;
        $alias = $this->alias;
        $name = $this->title;
        $title = $this->pageTitle ?: $this->title;
        $folderUrl = '';
        $palias = '';
        $pname = '';
        $ptitle = '';
        $trail = array($this->id, $pid);
        // Inherit the settings
        if ($this->type == 'root') {
            $objParentPage = $this;
            // see #4610
        } else {
            // Load all parent pages
            $objParentPage = \PageModel::findParentsById($pid);
            if ($objParentPage !== null) {
                while ($pid > 0 && $type != 'root' && $objParentPage->next()) {
                    $pid = $objParentPage->pid;
                    $type = $objParentPage->type;
                    // Parent title
                    if ($ptitle == '') {
                        $palias = $objParentPage->alias;
                        $pname = $objParentPage->title;
                        $ptitle = $objParentPage->pageTitle ?: $objParentPage->title;
                    }
                    // Page title
                    if ($type != 'root') {
                        $alias = $objParentPage->alias;
                        $name = $objParentPage->title;
                        $title = $objParentPage->pageTitle ?: $objParentPage->title;
                        $folderUrl = basename($alias) . '/' . $folderUrl;
                        $trail[] = $objParentPage->pid;
                    }
                    // Cache
                    if ($objParentPage->includeCache) {
                        $this->cache = $this->cache ?: $objParentPage->cache;
                        $this->clientCache = $this->clientCache ?: $objParentPage->clientCache;
                    }
                    // Layout
                    if ($objParentPage->includeLayout) {
                        if ($this->layout === false) {
                            $this->layout = $objParentPage->layout;
                        }
                        if ($this->mobileLayout === false) {
                            $this->mobileLayout = $objParentPage->mobileLayout;
                        }
                    }
                    // Protection
                    if ($objParentPage->protected && $this->protected === false) {
                        $this->protected = true;
                        $this->groups = \StringUtil::deserialize($objParentPage->groups);
                    }
                }
            }
            // Set the titles
            $this->mainAlias = $alias;
            $this->mainTitle = $name;
            $this->mainPageTitle = $title;
            $this->parentAlias = $palias;
            $this->parentTitle = $pname;
            $this->parentPageTitle = $ptitle;
            $this->folderUrl = $folderUrl;
        }
        // Set the root ID and title
        if ($objParentPage !== null && $objParentPage->type == 'root') {
            $this->rootId = $objParentPage->id;
            $this->rootAlias = $objParentPage->alias;
            $this->rootTitle = $objParentPage->title;
            $this->rootPageTitle = $objParentPage->pageTitle ?: $objParentPage->title;
            $this->domain = $objParentPage->dns;
            $this->rootLanguage = $objParentPage->language;
            $this->language = $objParentPage->language;
            $this->staticFiles = $objParentPage->staticFiles;
            $this->staticPlugins = $objParentPage->staticPlugins;
            $this->dateFormat = $objParentPage->dateFormat;
            $this->timeFormat = $objParentPage->timeFormat;
            $this->datimFormat = $objParentPage->datimFormat;
            $this->adminEmail = $objParentPage->adminEmail;
            // Store whether the root page has been published
            $time = \Date::floorToMinute();
            $this->rootIsPublic = $objParentPage->published && ($objParentPage->start == '' || $objParentPage->start <= $time) && ($objParentPage->stop == '' || $objParentPage->stop > $time + 60);
            $this->rootIsFallback = true;
            $this->rootUseSSL = $objParentPage->useSSL;
            $this->rootFallbackLanguage = $objParentPage->language;
            // Store the fallback language (see #6874)
            if (!$objParentPage->fallback) {
                $this->rootIsFallback = false;
                $this->rootFallbackLanguage = null;
                $objFallback = static::findPublishedFallbackByHostname($objParentPage->dns);
                if ($objFallback !== null) {
                    $this->rootFallbackLanguage = $objFallback->language;
                }
            }
        } elseif (TL_MODE == 'FE' && $this->type != 'root') {
            \System::log('Page ID "' . $this->id . '" does not belong to a root page', __METHOD__, TL_ERROR);
            throw new NoRootPageFoundException('No root page found');
        }
        $this->trail = array_reverse($trail);
        // Use the global date format if none is set (see #6104)
        if ($this->dateFormat == '') {
            $this->dateFormat = \Config::get('dateFormat');
        }
        if ($this->timeFormat == '') {
            $this->timeFormat = \Config::get('timeFormat');
        }
        if ($this->datimFormat == '') {
            $this->datimFormat = \Config::get('datimFormat');
        }
        // Prevent saving (see #6506 and #7199)
        $this->preventSaving();
        $this->blnDetailsLoaded = true;
        return $this;
    }

Usage Example

Пример #1
0
 /**
  * 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;
 }
All Usage Examples Of Contao\PageModel::loadDetails