Skip to content

Commit

Permalink
FEATURE: Refactor Redirect Adapter for Neos 9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dlubitz committed May 11, 2023
1 parent 24ad452 commit cb6ce03
Show file tree
Hide file tree
Showing 13 changed files with 535 additions and 630 deletions.
30 changes: 25 additions & 5 deletions Classes/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
* source code.
*/

use Neos\Flow\Persistence\Doctrine\PersistenceManager;
use Neos\RedirectHandler\NeosAdapter\Service\NodeRedirectService;
use Neos\EventStore\Model\EventEnvelope;
use Neos\Flow\Core\Bootstrap;
use Neos\Flow\Package\Package as BasePackage;
use Neos\ContentRepository\Domain\Model\Workspace;
use Neos\Neos\Domain\Model\SiteNodeName;
use Neos\Neos\FrontendRouting\Projection\DocumentUriPathProjection;
use Neos\RedirectHandler\NeosAdapter\Service\NodeRedirectService;

/**
* The Neos RedirectHandler NeosAdapter Package
Expand All @@ -32,7 +33,26 @@ public function boot(Bootstrap $bootstrap): void
{
$dispatcher = $bootstrap->getSignalSlotDispatcher();

$dispatcher->connect(Workspace::class, 'beforeNodePublishing', NodeRedirectService::class, 'collectPossibleRedirects');
$dispatcher->connect(PersistenceManager::class, 'allObjectsPersisted', NodeRedirectService::class, 'createPendingRedirects');
$dispatcher->connect(DocumentUriPathProjection::class, 'afterNodeAggregateWasMoved', function (
string $oldUriPath, string $newUriPath, SiteNodeName $siteNodeName, $_,
) use ($bootstrap) {
$nodeRedirectService = $bootstrap->getObjectManager()->get(NodeRedirectService::class);
$nodeRedirectService->createRedirect($oldUriPath, $newUriPath, $siteNodeName);
});

$dispatcher->connect(DocumentUriPathProjection::class, 'afterNodeAggregateWasRemoved', function (
string $oldUriPath, SiteNodeName $siteNodeName, $_,
) use ($bootstrap) {
$nodeRedirectService = $bootstrap->getObjectManager()->get(NodeRedirectService::class);
$nodeRedirectService->createRedirect($oldUriPath, null, $siteNodeName);
});

$dispatcher->connect(DocumentUriPathProjection::class, 'afterDocumentUriPathChanged', function (
string $oldUriPath, string $newUriPath, SiteNodeName $siteNodeName, $_, EventEnvelope $eventEnvelope,
) use ($bootstrap) {
$nodeRedirectService = $bootstrap->getObjectManager()->get(NodeRedirectService::class);
$nodeRedirectService->createRedirect($oldUriPath, $newUriPath, $siteNodeName);
});

}
}
Loading

0 comments on commit cb6ce03

Please sign in to comment.