Neos\Neos\Domain\Repository\SiteRepository::findDefault PHP Method

findDefault() public method

If the defaultSiteNodeName-setting is null the first active site is returned If the site is not found or not active an exception is thrown
public findDefault ( ) : Site
return Neos\Neos\Domain\Model\Site
    public function findDefault()
    {
        if ($this->defaultSiteNodeName === null) {
            return $this->findOnline()->getFirst();
        }
        /**
         * @var Site $defaultSite
         */
        $defaultSite = $this->findOneByNodeName($this->defaultSiteNodeName);
        if (!$defaultSite instanceof Site || $defaultSite->getState() !== Site::STATE_ONLINE) {
            throw new NeosException(sprintf('DefaultSiteNode %s not found or not active', $this->defaultSiteNodeName), 1476374818);
        }
        return $defaultSite;
    }

Usage Example

 /**
  * Determines the current domain and site from the request and sets the resulting values as
  * as defaults.
  *
  * @param array $defaultContextProperties
  * @return array
  */
 protected function setDefaultSiteAndDomainFromCurrentRequest(array $defaultContextProperties)
 {
     $currentDomain = $this->domainRepository->findOneByActiveRequest();
     if ($currentDomain !== null) {
         $defaultContextProperties['currentSite'] = $currentDomain->getSite();
         $defaultContextProperties['currentDomain'] = $currentDomain;
     } else {
         $defaultContextProperties['currentSite'] = $this->siteRepository->findDefault();
     }
     return $defaultContextProperties;
 }
All Usage Examples Of Neos\Neos\Domain\Repository\SiteRepository::findDefault