Skip to content
Open
4 changes: 2 additions & 2 deletions Classes/Command/TaxonomyCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function vocabulariesCommand(): void
$this->output->outputTable(
array_map(
fn(Node $node) => [
$node->nodeName?->value ?? $node->nodeAggregateId->value,
$node->name?->value ?? $node->aggregateId,
$node->getProperty('title'),
$node->getProperty('description')
],
Expand Down Expand Up @@ -93,7 +93,7 @@ private function subtreeToTableRowsRecursively(Subtree $subtree): array
{
$rows = array_map(fn(Subtree $subtree)=>$this->subtreeToTableRowsRecursively($subtree), $subtree->children);
$row = [
str_repeat(' ', $subtree->level) . ($subtree->node->nodeName?->value ?? $subtree->node->nodeAggregateId->value),
str_repeat(' ', $subtree->level) . ($subtree->node->name?->value ?? $subtree->node->aggregateId),
(string) $subtree->node->getProperty('title'),
(string) $subtree->node->getProperty('description')
];
Expand Down
110 changes: 58 additions & 52 deletions Classes/Controller/ModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
use Neos\Flow\Security\Context as SecurityContext;
use Neos\Fusion\View\FusionView;
use Neos\Neos\Domain\Service\WorkspaceNameBuilder;
use Neos\Neos\FrontendRouting\NodeAddressFactory;
use Neos\Neos\Fusion\Helper\DimensionHelper;
use Neos\Neos\Fusion\Helper\NodeHelper;
use Neos\Neos\Domain\NodeLabel\NodeLabelGeneratorInterface;
use Sitegeist\Taxonomy\Service\TaxonomyService;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAddress;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\Utility\Arrays;

/**
Expand Down Expand Up @@ -72,14 +74,15 @@ class ModuleController extends ActionController
#[Flow\Inject(lazy: false)]
protected SecurityContext $securityContext;

#[Flow\Inject]
protected NodeLabelGeneratorInterface $nodeLabelGenerator;

protected ContentRepository $contentRepository;

protected NodeAddressFactory $nodeAddressFactory;

public function initializeObject(): void
{
$this->contentRepository = $this->taxonomyService->getContentRepository();
$this->nodeAddressFactory = NodeAddressFactory::create($this->contentRepository);
}

public function initializeView(ViewInterface $view): void
Expand All @@ -106,8 +109,9 @@ public function indexAction(string $rootNodeAddress = null): void

$vocabularies = $this->taxonomyService->findAllVocabularies($subgraph);

$this->view->assign('contentRepositoryId', ContentRepositoryId::fromString('default'));
$this->view->assign('rootNode', $rootNode);
$this->view->assign('rootNodeAddress', $this->nodeAddressFactory->createFromNode($rootNode)->serializeForUri());
$this->view->assign('rootNodeAddress', NodeAddress::fromNode($rootNode)->toJson());
$this->view->assign('vocabularies', $vocabularies);
}

Expand Down Expand Up @@ -143,6 +147,7 @@ public function vocabularyAction(string $vocabularyNodeAddress): void
$rootNode = $this->taxonomyService->findOrCreateRoot($subgraph);
$vocabularySubtree = $this->taxonomyService->findSubtree($vocabularyNode);

$this->view->assign('contentRepositoryId', ContentRepositoryId::fromString('default'));
$this->view->assign('rootNode', $rootNode);
$this->view->assign('vocabularyNode', $vocabularyNode);
$this->view->assign('vocabularySubtree', $vocabularySubtree);
Expand Down Expand Up @@ -170,25 +175,25 @@ public function createVocabularyAction(string $rootNodeAddress, string $name, ar
$subgraph = $this->taxonomyService->getSubgraphForNode($rootNode);
$liveWorkspace = $this->taxonomyService->getLiveWorkspace();
$generalizations = $contentRepository->getVariationGraph()->getRootGeneralizations();
$nodeAddress = $this->nodeAddressFactory->createFromUriString($rootNodeAddress);
$nodeAddress = NodeAddress::fromJsonString($rootNodeAddress);

$originDimensionSpacePoint = OriginDimensionSpacePoint::fromDimensionSpacePoint($nodeAddress->dimensionSpacePoint);

// create node
$nodeAggregateId = NodeAggregateId::create();
$nodeTypeName = $this->taxonomyService->getVocabularyNodeTypeName();
$commandResult = $contentRepository->handle(
CreateNodeAggregateWithNode::create(
$liveWorkspace->currentContentStreamId,
$liveWorkspace->workspaceName,
$nodeAggregateId,
$nodeTypeName,
$originDimensionSpacePoint,
$rootNode->nodeAggregateId,
$rootNode->aggregateId,
null,
NodeName::transliterateFromString($name),
PropertyValuesToWrite::fromArray($properties)
)
);
$commandResult->block();
$commandResult;

// create required generalizations
foreach ($generalizations as $dimensionSpacePoint) {
Expand All @@ -199,7 +204,7 @@ public function createVocabularyAction(string $rootNodeAddress, string $name, ar

$contentRepository->handle(
CreateNodeVariant::create(
$liveWorkspace->currentContentStreamId,
$liveWorkspace->workspaceName,
$nodeAggregateId,
$originDimensionSpacePoint,
$originDimensionSpacePoint2
Expand All @@ -213,7 +218,7 @@ public function createVocabularyAction(string $rootNodeAddress, string $name, ar

if ($newVocabularyNode) {
$this->addFlashMessage(
sprintf('Created vocabulary %s', $newVocabularyNode->getLabel()),
sprintf('Created vocabulary %s', $this->nodeLabelGenerator->getLabel($newVocabularyNode)),
'Create Vocabulary'
);
}
Expand All @@ -227,12 +232,12 @@ public function createVocabularyAction(string $rootNodeAddress, string $name, ar
public function editVocabularyAction(string $vocabularyNodeAddress): void
{
$contentRepository = $this->taxonomyService->getContentRepository();
$liveWorkspace = $this->taxonomyService->getLiveWorkspace();
$vocabularyNode = $this->taxonomyService->getNodeByNodeAddress($vocabularyNodeAddress);

$subgraph = $contentRepository->getContentGraph()->getSubgraph(
$vocabularyNode->subgraphIdentity->contentStreamId,
$vocabularyNode->subgraphIdentity->dimensionSpacePoint,
$vocabularyNode->subgraphIdentity->visibilityConstraints,
$subgraph = $contentRepository->getContentGraph($liveWorkspace->workspaceName)->getSubgraph(
$vocabularyNode->dimensionSpacePoint,
$vocabularyNode->visibilityConstraints
);

$rootNode = $this->taxonomyService->findOrCreateRoot($subgraph);
Expand All @@ -250,39 +255,40 @@ public function updateVocabularyAction(string $vocabularyNodeAddress, string $na
{
$vocabularyNode = $this->taxonomyService->getNodeByNodeAddress($vocabularyNodeAddress);
$subgraph = $this->taxonomyService->getSubgraphForNode($vocabularyNode);
$liveWorkspace = $this->taxonomyService->getLiveWorkspace();
$rootNode = $this->taxonomyService->findOrCreateRoot($subgraph);

$commandResult = $this->contentRepository->handle(
SetNodeProperties::create(
$vocabularyNode->subgraphIdentity->contentStreamId,
$vocabularyNode->nodeAggregateId,
$liveWorkspace->workspaceName,
$vocabularyNode->aggregateId,
$vocabularyNode->originDimensionSpacePoint,
PropertyValuesToWrite::fromArray($properties)
)
);

if ($name != $vocabularyNode->nodeName?->value) {
if ($name != $vocabularyNode->name?->value) {
$commandResult = $this->contentRepository->handle(
ChangeNodeAggregateName::create(
$vocabularyNode->subgraphIdentity->contentStreamId,
$vocabularyNode->nodeAggregateId,
$liveWorkspace->workspaceName,
$vocabularyNode->aggregateId,
NodeName::transliterateFromString($name)
)
);
}

$commandResult->block();
$commandResult;
$this->rebaseCurrentUserWorkspace();

$updatedVocabularyNode = $subgraph->findNodeById($vocabularyNode->nodeAggregateId);
$updatedVocabularyNode = $subgraph->findNodeById($vocabularyNode->aggregateId);

if ($updatedVocabularyNode) {
$this->addFlashMessage(
sprintf('Updated vocabulary %s', $updatedVocabularyNode->getLabel())
sprintf('Updated vocabulary %s', $this->nodeLabelGenerator->getLabel($updatedVocabularyNode))
);
}

$this->redirect('index', null, null, ['rootNodeAddress' => $this->nodeAddressFactory->createFromNode($rootNode)]);
$this->redirect('index', null, null, ['rootNodeAddress' => NodeAddress::fromNode($rootNode)]);
}

/**
Expand All @@ -297,20 +303,20 @@ public function deleteVocabularyAction(string $vocabularyNodeAddress): void

$commandResult = $this->contentRepository->handle(
RemoveNodeAggregate::create(
$liveWorkspace->currentContentStreamId,
$vocabularyNode->nodeAggregateId,
$liveWorkspace->workspaceName,
$vocabularyNode->aggregateId,
$vocabularyNode->originDimensionSpacePoint->toDimensionSpacePoint(),
NodeVariantSelectionStrategy::STRATEGY_ALL_VARIANTS
)
);
$commandResult->block();
$commandResult;
$this->rebaseCurrentUserWorkspace();

$this->addFlashMessage(
sprintf('Deleted vocabulary %s', $vocabularyNode->getLabel())
sprintf('Deleted vocabulary %s', $this->nodeLabelGenerator->getLabel($vocabularyNode))
);

$this->redirect('index', null, null, ['rootNodeAddress' => $this->nodeAddressFactory->createFromNode($rootNode)]);
$this->redirect('index', null, null, ['rootNodeAddress' => NodeAddress::fromNode($rootNode)]);
}

/**
Expand Down Expand Up @@ -351,25 +357,24 @@ public function createTaxonomyAction(string $parentNodeAddress, string $name, ar
$liveWorkspace = $this->taxonomyService->getLiveWorkspace();

$generalizations = $this->contentRepository->getVariationGraph()->getRootGeneralizations();
$nodeAddress = $this->nodeAddressFactory->createFromUriString($parentNodeAddress);
$nodeAddress = NodeAddress::fromJsonString($parentNodeAddress);
$originDimensionSpacePoint = OriginDimensionSpacePoint::fromDimensionSpacePoint($nodeAddress->dimensionSpacePoint);

// create node
$nodeAggregateId = NodeAggregateId::create();
$nodeTypeName = $this->taxonomyService->getTaxonomyNodeTypeName();
$commandResult = $this->contentRepository->handle(
CreateNodeAggregateWithNode::create(
$liveWorkspace->currentContentStreamId,
$liveWorkspace->workspaceName,
$nodeAggregateId,
$nodeTypeName,
$originDimensionSpacePoint,
$parentNode->nodeAggregateId,
$parentNode->aggregateId,
null,
NodeName::transliterateFromString($name),
PropertyValuesToWrite::fromArray($properties)
)
);
$commandResult->block();
$commandResult;

// create required generalizations
foreach ($generalizations as $dimensionSpacePoint) {
Expand All @@ -378,9 +383,9 @@ public function createTaxonomyAction(string $parentNodeAddress, string $name, ar
continue;
}

$commandResult = $this->contentRepository->handle(
$this->contentRepository->handle(
CreateNodeVariant::create(
$liveWorkspace->currentContentStreamId,
$liveWorkspace->workspaceName,
$nodeAggregateId,
$originDimensionSpacePoint,
$originDimensionSpacePoint2
Expand All @@ -393,7 +398,7 @@ public function createTaxonomyAction(string $parentNodeAddress, string $name, ar

if ($newTaxonomyNode) {
$this->addFlashMessage(
sprintf('Created taxonomy %s', $newTaxonomyNode->getLabel()),
sprintf('Created taxonomy %s', $this->nodeLabelGenerator->getLabel($newTaxonomyNode)),
'Create taxomony'
);
}
Expand All @@ -402,7 +407,7 @@ public function createTaxonomyAction(string $parentNodeAddress, string $name, ar
'vocabulary',
null,
null,
['vocabularyNodeAddress' => $this->nodeAddressFactory->createFromNode($vocabularyNode)]
['vocabularyNodeAddress' => NodeAddress::fromNode($vocabularyNode)]
);
}

Expand All @@ -428,36 +433,37 @@ public function updateTaxonomyAction(string $taxonomyNodeAddress, string $name,
$taxonomyNode = $this->taxonomyService->getNodeByNodeAddress($taxonomyNodeAddress);
$vocabularyNode = $this->taxonomyService->findVocabularyForNode($taxonomyNode);
$subgraph = $this->taxonomyService->getSubgraphForNode($taxonomyNode);
$liveWorkspace = $this->taxonomyService->getLiveWorkspace();

$commandResult = $this->contentRepository->handle(
SetNodeProperties::create(
$taxonomyNode->subgraphIdentity->contentStreamId,
$taxonomyNode->nodeAggregateId,
$liveWorkspace->workspaceName,
$taxonomyNode->aggregateId,
$taxonomyNode->originDimensionSpacePoint,
PropertyValuesToWrite::fromArray($properties)
)
);
if ($name != $taxonomyNode->nodeName?->value) {
if ($name != $taxonomyNode->name?->value) {
$commandResult = $this->contentRepository->handle(
ChangeNodeAggregateName::create(
$taxonomyNode->subgraphIdentity->contentStreamId,
$taxonomyNode->nodeAggregateId,
$liveWorkspace->workspaceName,
$taxonomyNode->aggregateId,
NodeName::transliterateFromString($name)
)
);
}
$commandResult->block();
$commandResult;
$this->rebaseCurrentUserWorkspace();

$updatedTaxonomyNode = $subgraph->findNodeById($vocabularyNode->nodeAggregateId);
$updatedTaxonomyNode = $subgraph->findNodeById($vocabularyNode->aggregateId);

if ($updatedTaxonomyNode) {
$this->addFlashMessage(
sprintf('Updated taxonomy %s', $updatedTaxonomyNode->getLabel())
sprintf('Updated taxonomy %s', $this->nodeLabelGenerator->getLabel($updatedTaxonomyNode))
);
}

$this->redirect('vocabulary', null, null, ['vocabularyNodeAddress' => $this->nodeAddressFactory->createFromNode($vocabularyNode)]);
$this->redirect('vocabulary', null, null, ['vocabularyNodeAddress' => NodeAddress::fromNode($vocabularyNode)]);
}

/**
Expand All @@ -471,20 +477,20 @@ public function deleteTaxonomyAction(string $taxonomyNodeAddress): void

$commandResult = $this->contentRepository->handle(
RemoveNodeAggregate::create(
$liveWorkspace->currentContentStreamId,
$taxonomyNode->nodeAggregateId,
$liveWorkspace->workspaceName,
$taxonomyNode->aggregateId,
$taxonomyNode->originDimensionSpacePoint->toDimensionSpacePoint(),
NodeVariantSelectionStrategy::STRATEGY_ALL_VARIANTS
)
);
$commandResult->block();
$commandResult;
$this->rebaseCurrentUserWorkspace();

$this->addFlashMessage(
sprintf('Deleted taxonomy %s', $taxonomyNode->getLabel())
sprintf('Deleted taxonomy %s', $this->nodeLabelGenerator->getLabel($taxonomyNode))
);

$this->redirect('vocabulary', null, null, ['vocabularyNodeAddress' => $this->nodeAddressFactory->createFromNode($vocabularyNode)]);
$this->redirect('vocabulary', null, null, ['vocabularyNodeAddress' => NodeAddress::fromNode($vocabularyNode)]);
}

protected function rebaseCurrentUserWorkspace(): void
Expand Down
18 changes: 14 additions & 4 deletions Classes/Controller/SecondaryInspectorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

use Neos\ContentRepository\Core\Projection\ContentGraph\AbsoluteNodePath;
use Neos\ContentRepository\Core\Projection\ContentGraph\Subtree;
use Neos\Neos\Domain\NodeLabel\NodeLabelGeneratorInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\Controller\ActionController;
use Neos\Flow\Mvc\View\JsonView;
use Sitegeist\Taxonomy\Service\TaxonomyService;
use Neos\Neos\Ui\ContentRepository\Service\NeosUiNodeService;
use Neos\Neos\FrontendRouting\SiteDetection\SiteDetectionResult;

/**
* Class SecondaryInspectorController
Expand All @@ -34,6 +37,12 @@ class SecondaryInspectorController extends ActionController
*/
protected $taxonomyService;

#[Flow\Inject]
protected NodeLabelGeneratorInterface $nodeLabelGenerator;

#[Flow\Inject]
protected NeosUiNodeService $nodeService;

/**
* @var string[]
*/
Expand All @@ -46,7 +55,8 @@ class SecondaryInspectorController extends ActionController

public function treeAction(string $contextNode, string $startingPoint): void
{
$node = $this->taxonomyService->getNodeByNodeAddress($contextNode);
$contentRepositoryId = SiteDetectionResult::fromRequest($this->request->getHttpRequest())->contentRepositoryId;
$node = $this->nodeService->findNodeBySerializedNodeAddress($contextNode, $contentRepositoryId);
$subgraph = $this->taxonomyService->getSubgraphForNode($node);

$path = AbsoluteNodePath::fromString($startingPoint);
Expand All @@ -66,10 +76,10 @@ public function treeAction(string $contextNode, string $startingPoint): void
*/
protected function toJson(Subtree $subtree, string $pathSoFar = null): array
{
$label = $subtree->node->getLabel();
$pathSegment = $subtree->node->nodeName?->value ?? $label;
$label = $this->nodeLabelGenerator->getLabel($subtree->node);
$pathSegment = $subtree->node->name?->value ?? $label;
$path = $pathSoFar ? $pathSoFar . ' - ' . $pathSegment : $pathSegment;
$identifier = $subtree->node->nodeAggregateId->value;
$identifier = $subtree->node->aggregateId;
$nodeType = $subtree->node->nodeTypeName->value;
$title = $subtree->node->getProperty('title');
$description = $subtree->node->getProperty('description');
Expand Down
Loading