Set properties of site / rootNode in CommandController

Hi there,

I’ve got a CommandController that fetches some data from an API. Now I want to update a property on my root page ${q(site)}.

In my CommanController I’ve got something like this:

$contentContext = $this->contextFactory->create(array(
    'workspaceName' => 'live',
    //'currentSite' => $node->getContext()->getCurrentSite()
));

\Neos\Flow\var_dump($contentContext->getRootNode());

Since I’m not really on a node, there is no $node. Also $contentContext->getRootNode() is not the correct node, so $contentContext->getRootNode()->getProperties() returns not the correct properties.

What am I missing here? :slight_smile:

Thanks in advance and have a nice day :sunny:

Since your command controller has no request to determine the “current site” from, this won’t work automagically. But you can fetch the node by path from /sites/sitenodename . That should work…

protected function createContext(string $workspaceName): ?ContentContext
{
    $contextProperties = [
        'workspaceName' => $workspaceName,
        'invisibleContentShown' => true,
        'inaccessibleContentShown' => true
    ];

    $currentDomain = $this->domainRepository->findOneByActiveRequest();

    if ($currentDomain !== null) {
        $contextProperties['currentSite'] = $currentDomain->getSite();
        $contextProperties['currentDomain'] = $currentDomain;
    } else {
        $contextProperties['currentSite'] = $this->siteRepository->findFirstOnline();
    }

    return $this->contextFactory->create($contextProperties);
}