14
14
use Doctrine \Common \Util \ClassUtils ;
15
15
use Doctrine \ODM \PHPCR \Document \Generic ;
16
16
use Doctrine \ODM \PHPCR \DocumentManager ;
17
+ use Symfony \Cmf \Bundle \RoutingAutoBundle \Model \AutoRoute ;
18
+ use Symfony \Cmf \Component \Routing \RouteReferrersInterface ;
17
19
use Symfony \Cmf \Component \RoutingAuto \AdapterInterface ;
18
20
use Symfony \Cmf \Component \RoutingAuto \Model \AutoRouteInterface ;
19
21
use Symfony \Cmf \Component \RoutingAuto \UriContext ;
@@ -157,13 +159,18 @@ public function createAutoRoute(UriContext $uriContext, $contentDocument, $local
157
159
);
158
160
}
159
161
162
+ /** @var AutoRoute $headRoute */
160
163
$ headRoute = new $ this ->autoRouteFqcn ();
161
164
$ headRoute ->setContent ($ contentDocument );
162
165
$ headRoute ->setName ($ headName );
163
166
$ headRoute ->setParentDocument ($ document );
164
167
$ headRoute ->setLocale ($ locale );
165
168
$ headRoute ->setType (AutoRouteInterface::TYPE_PRIMARY );
166
169
170
+ if ($ contentDocument instanceof RouteReferrersInterface) {
171
+ $ contentDocument ->addRoute ($ headRoute );
172
+ }
173
+
167
174
foreach ($ uriContext ->getDefaults () as $ key => $ value ) {
168
175
$ headRoute ->setDefault ($ key , $ value );
169
176
}
@@ -256,6 +263,7 @@ private function migrateGenericToAutoRoute(Generic $document, $contentDocument,
256
263
$ this ->dm ->getPhpcrSession ()->save ();
257
264
// Detach is needed to force Doctrine to re-load the node
258
265
$ this ->dm ->detach ($ document );
266
+ /** @var AutoRoute $autoRoute */
259
267
$ autoRoute = $ this ->dm ->find (null , $ document ->getId ());
260
268
261
269
if (!$ autoRoute instanceof $ autoRouteClassName ) {
@@ -272,6 +280,9 @@ private function migrateGenericToAutoRoute(Generic $document, $contentDocument,
272
280
$ autoRoute ->setContent ($ contentDocument );
273
281
$ autoRoute ->setLocale ($ locale );
274
282
$ autoRoute ->setType ($ routeType );
283
+ if ($ contentDocument instanceof RouteReferrersInterface) {
284
+ $ contentDocument ->addRoute ($ autoRoute );
285
+ }
275
286
276
287
return $ autoRoute ;
277
288
}
0 commit comments