Neos\Neos\Controller\Backend\MenuHelper::buildSiteList PHP Method

buildSiteList() public method

Build a list of sites
public buildSiteList ( ControllerContext $controllerContext ) : array
$controllerContext Neos\Flow\Mvc\Controller\ControllerContext
return array
    public function buildSiteList(ControllerContext $controllerContext)
    {
        $requestUriHost = $controllerContext->getRequest()->getHttpRequest()->getUri()->getHost();
        $domainsFound = false;
        $sites = array();
        foreach ($this->siteRepository->findOnline() as $site) {
            $uri = null;
            $active = false;
            /** @var $site Site */
            if ($site->hasActiveDomains()) {
                $activeHostPatterns = $site->getActiveDomains()->map(function ($domain) {
                    return $domain->getHostPattern();
                })->toArray();
                $active = in_array($requestUriHost, $activeHostPatterns, true);
                if ($active) {
                    $uri = $controllerContext->getUriBuilder()->reset()->setCreateAbsoluteUri(true)->uriFor('index', array(), 'Backend\\Backend', 'Neos.Neos');
                } else {
                    $uri = $controllerContext->getUriBuilder()->reset()->uriFor('switchSite', array('site' => $site), 'Backend\\Backend', 'Neos.Neos');
                }
                $domainsFound = true;
            }
            $sites[] = array('name' => $site->getName(), 'nodeName' => $site->getNodeName(), 'uri' => $uri, 'active' => $active);
        }
        if ($domainsFound === false) {
            $uri = $controllerContext->getUriBuilder()->reset()->setCreateAbsoluteUri(true)->uriFor('index', array(), 'Backend\\Backend', 'Neos.Neos');
            $sites[0]['uri'] = $uri;
        }
        return $sites;
    }

Usage Example

 /**
  * @param NodeInterface $node
  * @return string
  * @throws NeosException
  */
 public function render(NodeInterface $node)
 {
     if ($this->privilegeManager->isPrivilegeTargetGranted('Neos.Neos:Backend.GeneralAccess') === false) {
         return '';
     }
     /** @var $actionRequest ActionRequest */
     $actionRequest = $this->controllerContext->getRequest();
     $innerView = new StandaloneView($actionRequest);
     $innerView->setTemplatePathAndFilename('resource://Neos.Neos/Private/Templates/Backend/Content/Container.html');
     $innerView->setFormat('html');
     $innerView->setPartialRootPath('resource://Neos.Neos/Private/Partials');
     $user = $this->partyService->getAssignedPartyOfAccount($this->securityContext->getAccount());
     $innerView->assignMultiple(array('node' => $node, 'modules' => $this->menuHelper->buildModuleList($this->controllerContext), 'sites' => $this->menuHelper->buildSiteList($this->controllerContext), 'user' => $user));
     return $innerView->render();
 }
All Usage Examples Of Neos\Neos\Controller\Backend\MenuHelper::buildSiteList