Skip to content

Commit

Permalink
TASK: Utilize Neos.Neos:Site at various places
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Oct 12, 2023
1 parent 526aee3 commit c2dbecb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public function canEvaluate($context)
*
* @param FlowQuery<int,mixed> $flowQuery the FlowQuery object
* @param array<int,mixed> $arguments the arguments for this operation
* @todo Compare to node type Neos.Neos:Site instead of path once it is available
* @return void
*/
public function evaluate(FlowQuery $flowQuery, array $arguments)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,8 @@ protected function computeSiteChanges(Workspace $selectedWorkspace, ContentRepos
if (is_null($documentNode)) {
$documentNode = $ancestor;
}
// the site node is the last ancestor of type Document
}
if ($this->getNodeType($ancestor)->isOfType(NodeTypeNameFactory::NAME_SITE)) {
$siteNode = $documentNode;
}
}
Expand Down
14 changes: 14 additions & 0 deletions Neos.Neos/Classes/Domain/Repository/SiteRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
namespace Neos\Neos\Domain\Repository;

use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Persistence\QueryInterface;
use Neos\Flow\Persistence\QueryResultInterface;
use Neos\Flow\Persistence\Repository;
use Neos\Neos\Domain\Model\Site;
use Neos\Neos\Domain\Exception as NeosException;
use Neos\Neos\Domain\Model\SiteNodeName;
use Neos\Neos\Domain\Service\NodeTypeNameFactory;
use Neos\Neos\Utility\NodeTypeWithFallbackProvider;

/**
* The Site Repository
Expand All @@ -33,6 +36,11 @@
*/
class SiteRepository extends Repository
{
use NodeTypeWithFallbackProvider;

#[Flow\Inject]
protected ContentRepositoryRegistry $contentRepositoryRegistry;

/**
* @var array<string,string>
*/
Expand Down Expand Up @@ -95,8 +103,14 @@ public function findOneByNodeName(string|SiteNodeName $nodeName): ?Site
return $site;
}

/**
* @throws \Neos\Neos\Domain\Exception in case the passed $siteNode is not a real site node or no site matches this site node.
*/
public function findSiteBySiteNode(Node $siteNode): Site
{
if (!$this->getNodeType($siteNode)->isOfType(NodeTypeNameFactory::NAME_SITE)) {
throw new \Neos\Neos\Domain\Exception(sprintf('Node %s is not a site node. Site nodes must be of type "%s".', $siteNode->nodeAggregateId->value, NodeTypeNameFactory::NAME_SITE), 1697108987);
}
if ($siteNode->nodeName === null) {
throw new \Neos\Neos\Domain\Exception(sprintf('Site node "%s" is unnamed', $siteNode->nodeAggregateId->value), 1681286146);
}
Expand Down
21 changes: 6 additions & 15 deletions Neos.Neos/Classes/Fusion/Helper/SiteHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@

namespace Neos\Neos\Fusion\Helper;

use Neos\ContentRepository\Core\Projection\ContentGraph\NodePath;
use Neos\Neos\Domain\Model\Site;
use Neos\Neos\Domain\Model\SiteNodeName;
use Neos\Neos\Domain\Repository\SiteRepository;
use Neos\Neos\FrontendRouting\NodeAddressFactory;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Eel\ProtectedContextAwareInterface;
use Neos\Neos\Domain\Exception;
use Neos\Flow\Annotations as Flow;
use Neos\Neos\Domain\Model\Site;
use Neos\Neos\Domain\Repository\SiteRepository;

/**
* Eel helper for accessing the Site object
Expand All @@ -36,17 +31,13 @@ class SiteHelper implements ProtectedContextAwareInterface
*/
protected $siteRepository;

/**
*
* @throws Exception
*/
public function findBySiteNode(Node $siteNode): ?Site
{
if ($siteNode->nodeName === null) {
try {
return $this->siteRepository->findSiteBySiteNode($siteNode);
} catch (\Neos\Neos\Domain\Exception) {
return null;
}
$siteNodeName = SiteNodeName::fromNodeName($siteNode->nodeName);
return $this->siteRepository->findOneByNodeName($siteNodeName);
}

/**
Expand Down

0 comments on commit c2dbecb

Please sign in to comment.