Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request #207 from symfony-cmf/backlink-route
Browse files Browse the repository at this point in the history
update content if it implements the addRoute method
  • Loading branch information
dbu authored Aug 15, 2017
2 parents 72bd73c + 6390139 commit 394d142
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

2.0.0-RC3 (unreleased)
----------------------

* PhpcrOdmAdapter now updates the content document with the new route, if the
content implements RouteReferrersInterface.

2.0.0-RC1
---------

Expand Down
11 changes: 11 additions & 0 deletions src/Adapter/PhpcrOdmAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Doctrine\Common\Util\ClassUtils;
use Doctrine\ODM\PHPCR\Document\Generic;
use Doctrine\ODM\PHPCR\DocumentManager;
use Symfony\Cmf\Bundle\RoutingAutoBundle\Model\AutoRoute;
use Symfony\Cmf\Component\Routing\RouteReferrersInterface;
use Symfony\Cmf\Component\RoutingAuto\AdapterInterface;
use Symfony\Cmf\Component\RoutingAuto\Model\AutoRouteInterface;
use Symfony\Cmf\Component\RoutingAuto\UriContext;
Expand Down Expand Up @@ -157,13 +159,18 @@ public function createAutoRoute(UriContext $uriContext, $contentDocument, $local
);
}

/** @var AutoRoute $headRoute */
$headRoute = new $this->autoRouteFqcn();
$headRoute->setContent($contentDocument);
$headRoute->setName($headName);
$headRoute->setParentDocument($document);
$headRoute->setLocale($locale);
$headRoute->setType(AutoRouteInterface::TYPE_PRIMARY);

if ($contentDocument instanceof RouteReferrersInterface) {
$contentDocument->addRoute($headRoute);
}

foreach ($uriContext->getDefaults() as $key => $value) {
$headRoute->setDefault($key, $value);
}
Expand Down Expand Up @@ -256,6 +263,7 @@ private function migrateGenericToAutoRoute(Generic $document, $contentDocument,
$this->dm->getPhpcrSession()->save();
// Detach is needed to force Doctrine to re-load the node
$this->dm->detach($document);
/** @var AutoRoute $autoRoute */
$autoRoute = $this->dm->find(null, $document->getId());

if (!$autoRoute instanceof $autoRouteClassName) {
Expand All @@ -272,6 +280,9 @@ private function migrateGenericToAutoRoute(Generic $document, $contentDocument,
$autoRoute->setContent($contentDocument);
$autoRoute->setLocale($locale);
$autoRoute->setType($routeType);
if ($contentDocument instanceof RouteReferrersInterface) {
$contentDocument->addRoute($autoRoute);
}

return $autoRoute;
}
Expand Down

0 comments on commit 394d142

Please sign in to comment.