@@ -72,13 +72,8 @@ private function setupDynamicRouter(array $config, ContainerBuilder $container,
72
72
$ container ->setParameter ($ this ->getAlias () . '.controllers_by_type ' , $ config ['controllers_by_type ' ]);
73
73
$ container ->setParameter ($ this ->getAlias () . '.controllers_by_class ' , $ config ['controllers_by_class ' ]);
74
74
$ container ->setParameter ($ this ->getAlias () . '.templates_by_class ' , $ config ['templates_by_class ' ]);
75
- // if the content class defines the template, we also need to make sure we use the generic controller for those routes
76
- $ controllerForTemplates = array ();
77
- foreach ($ config ['templates_by_class ' ] as $ key => $ value ) {
78
- $ controllerForTemplates [$ key ] = $ config ['generic_controller ' ];
79
- }
80
- $ container ->setParameter ($ this ->getAlias () . '.defined_templates_class ' , $ controllerForTemplates );
81
75
$ container ->setParameter ($ this ->getAlias () . '.uri_filter_regexp ' , $ config ['uri_filter_regexp ' ]);
76
+
82
77
$ locales = false ;
83
78
if (isset ($ config ['locales ' ])) {
84
79
$ locales = $ config ['locales ' ];
@@ -131,9 +126,21 @@ private function setupDynamicRouter(array $config, ContainerBuilder $container,
131
126
if (!empty ($ config ['controllers_by_class ' ])) {
132
127
$ dynamic ->addMethodCall ('addRouteEnhancer ' , array (new Reference ($ this ->getAlias () . '.enhancer_controllers_by_class ' )));
133
128
}
134
- if (! empty ( $ config [ ' generic_controller ' ]) && ! empty ( $ config [ ' templates_by_class ' ])) {
135
- $ dynamic -> addMethodCall ( ' addRouteEnhancer ' , array ( new Reference ( $ this -> getAlias () . ' .enhancer_controller_for_templates_by_class ' )));
129
+
130
+ if (! empty ( $ config [ ' templates_by_class ' ])) {
136
131
$ dynamic ->addMethodCall ('addRouteEnhancer ' , array (new Reference ($ this ->getAlias () . '.enhancer_templates_by_class ' )));
132
+
133
+ if (null === $ config ['generic_controller ' ]) {
134
+ throw new InvalidConfigurationException ('If you configure templates_by_class, you need to configure a generic_router. If you are sure you do not need a generic router, set the field to false to disable explicitly. ' );
135
+ } elseif (is_string ($ config ['generic_controller ' ])) {
136
+ // if the content class defines the template, we also need to make sure we use the generic controller for those routes
137
+ $ controllerForTemplates = array ();
138
+ foreach ($ config ['templates_by_class ' ] as $ key => $ value ) {
139
+ $ controllerForTemplates [$ key ] = $ config ['generic_controller ' ];
140
+ }
141
+ $ container ->setParameter ($ this ->getAlias () . '.defined_templates_class ' , $ controllerForTemplates );
142
+ $ dynamic ->addMethodCall ('addRouteEnhancer ' , array (new Reference ($ this ->getAlias () . '.enhancer_controller_for_templates_by_class ' )));
143
+ }
137
144
}
138
145
if (!empty ($ config ['route_filters_by_id ' ])) {
139
146
$ matcher = $ container ->getDefinition ('cmf_routing.nested_matcher ' );
0 commit comments