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

Commit 394d142

Browse files
authored
Merge pull request #207 from symfony-cmf/backlink-route
update content if it implements the addRoute method
2 parents 72bd73c + 6390139 commit 394d142

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
=========
33

4+
2.0.0-RC3 (unreleased)
5+
----------------------
6+
7+
* PhpcrOdmAdapter now updates the content document with the new route, if the
8+
content implements RouteReferrersInterface.
9+
410
2.0.0-RC1
511
---------
612

src/Adapter/PhpcrOdmAdapter.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Doctrine\Common\Util\ClassUtils;
1515
use Doctrine\ODM\PHPCR\Document\Generic;
1616
use Doctrine\ODM\PHPCR\DocumentManager;
17+
use Symfony\Cmf\Bundle\RoutingAutoBundle\Model\AutoRoute;
18+
use Symfony\Cmf\Component\Routing\RouteReferrersInterface;
1719
use Symfony\Cmf\Component\RoutingAuto\AdapterInterface;
1820
use Symfony\Cmf\Component\RoutingAuto\Model\AutoRouteInterface;
1921
use Symfony\Cmf\Component\RoutingAuto\UriContext;
@@ -157,13 +159,18 @@ public function createAutoRoute(UriContext $uriContext, $contentDocument, $local
157159
);
158160
}
159161

162+
/** @var AutoRoute $headRoute */
160163
$headRoute = new $this->autoRouteFqcn();
161164
$headRoute->setContent($contentDocument);
162165
$headRoute->setName($headName);
163166
$headRoute->setParentDocument($document);
164167
$headRoute->setLocale($locale);
165168
$headRoute->setType(AutoRouteInterface::TYPE_PRIMARY);
166169

170+
if ($contentDocument instanceof RouteReferrersInterface) {
171+
$contentDocument->addRoute($headRoute);
172+
}
173+
167174
foreach ($uriContext->getDefaults() as $key => $value) {
168175
$headRoute->setDefault($key, $value);
169176
}
@@ -256,6 +263,7 @@ private function migrateGenericToAutoRoute(Generic $document, $contentDocument,
256263
$this->dm->getPhpcrSession()->save();
257264
// Detach is needed to force Doctrine to re-load the node
258265
$this->dm->detach($document);
266+
/** @var AutoRoute $autoRoute */
259267
$autoRoute = $this->dm->find(null, $document->getId());
260268

261269
if (!$autoRoute instanceof $autoRouteClassName) {
@@ -272,6 +280,9 @@ private function migrateGenericToAutoRoute(Generic $document, $contentDocument,
272280
$autoRoute->setContent($contentDocument);
273281
$autoRoute->setLocale($locale);
274282
$autoRoute->setType($routeType);
283+
if ($contentDocument instanceof RouteReferrersInterface) {
284+
$contentDocument->addRoute($autoRoute);
285+
}
275286

276287
return $autoRoute;
277288
}

0 commit comments

Comments
 (0)