Skip to content

Commit 98a70fe

Browse files
committed
Merge pull request #210 from symfony-cmf/cleanup-routing
port features from simple cms into routing bundle to simplify things
2 parents abbe0e1 + 2c9293e commit 98a70fe

40 files changed

+1887
-534
lines changed

Admin/RedirectRouteAdmin.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
1312
namespace Symfony\Cmf\Bundle\RoutingBundle\Admin;
1413

1514
use Sonata\AdminBundle\Datagrid\DatagridMapper;
@@ -31,7 +30,7 @@ class RedirectRouteAdmin extends Admin
3130
protected function configureListFields(ListMapper $listMapper)
3231
{
3332
$listMapper
34-
->addIdentifier('id', 'text')
33+
->addIdentifier('path', 'text')
3534
;
3635
}
3736

@@ -44,14 +43,15 @@ protected function configureFormFields(FormMapper $formMapper)
4443
->add('routeName', 'text', array('required' => false))
4544
->add('uri', 'text', array('required' => false))
4645
->add('routeTarget', 'doctrine_phpcr_odm_tree', array('choice_list' => array(), 'required' => false, 'root_node' => $this->routeRoot))
47-
->end();
46+
->end()
47+
;
4848
}
4949

5050
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
5151
{
5252
$datagridMapper
5353
->add('name', 'doctrine_phpcr_nodename')
54-
;
54+
;
5555
}
5656

5757
public function setRouteRoot($routeRoot)
@@ -69,6 +69,6 @@ public function toString($object)
6969
return $object instanceof Route && $object->getId()
7070
? $object->getId()
7171
: $this->trans('link_add', array(), 'SonataAdminBundle')
72-
;
72+
;
7373
}
7474
}

Admin/RouteAdmin.php

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,26 @@ protected function configureFormFields(FormMapper $formMapper)
6666
array('choice_list' => array(), 'select_root_node' => true, 'root_node' => $this->routeRoot)
6767
)
6868
->add('name', 'text')
69-
->add('addFormatPattern', null, array('required' => false, 'help' => 'form.help_add_format_pattern'))
70-
->add('addTrailingSlash', null, array('required' => false, 'help' => 'form.help_add_trailing_slash'))
7169
->end();
7270

7371
if (null === $this->getParentFieldDescription()) {
7472
$formMapper
7573
->with('form.group_general')
76-
->add('variablePattern', 'text', array('required' => false))
77-
->add('content', 'doctrine_phpcr_odm_tree', array('choice_list' => array(), 'required' => false, 'root_node' => $this->contentRoot))
78-
->add('defaults', 'sonata_type_immutable_array', array('keys' => $this->configureFieldsForDefaults()))
74+
->add('content', 'doctrine_phpcr_odm_tree', array('choice_list' => array(), 'required' => false, 'root_node' => $this->contentRoot))
75+
->end()
76+
->with('form.group_advanced')
77+
->add('variablePattern', 'text', array('required' => false), array('help' => 'form.help_variable_pattern'))
78+
->add('defaults', 'sonata_type_immutable_array', array('keys' => $this->configureFieldsForDefaults()))
79+
->add('options', 'sonata_type_immutable_array', array('keys' => $this->configureFieldsForOptions()), array('help' => 'form.help_options'))
80+
->end()
7981
->end();
8082
}
8183
}
8284

8385
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
8486
{
8587
$datagridMapper
86-
->add('name', 'doctrine_phpcr_string');
88+
->add('name', 'doctrine_phpcr_nodename');
8789
}
8890

8991
public function setRouteRoot($routeRoot)
@@ -110,7 +112,7 @@ public function getExportFormats()
110112

111113
protected function configureFieldsForDefaults()
112114
{
113-
$defaults = array(
115+
$defaults = array(
114116
'_controller' => array('_controller', 'text', array('required' => false)),
115117
'_template' => array('_template', 'text', array('required' => false)),
116118
'type' => array('type', 'cmf_routing_route_type', array(
@@ -125,7 +127,7 @@ protected function configureFieldsForDefaults()
125127
$defaults[$name] = array($name, 'text', array('required' => false));
126128
}
127129
}
128-
130+
129131
//parse variable pattern and add defaults for it - taken from routecompiler
130132
/** @var $route Route */
131133
$route = $this->subject;
@@ -142,6 +144,24 @@ protected function configureFieldsForDefaults()
142144
return $defaults;
143145
}
144146

147+
protected function configureFieldsForOptions()
148+
{
149+
$options = array(
150+
array('add_locale_pattern', 'checkbox', array('required' => false, 'label' => 'form.label_add_locale_pattern', 'translation_domain' => $this->translationDomain)),
151+
array('add_format_pattern', 'checkbox', array('required' => false, 'label' => 'form.label_add_format_pattern', 'translation_domain' => $this->translationDomain)),
152+
array('add_trailing_slash', 'checkbox', array('required' => false, 'label' => 'form.label_add_trailing_slash', 'translation_domain' => $this->translationDomain)),
153+
);
154+
155+
$dynamicOptions = $this->getSubject()->getOptions();
156+
foreach ($dynamicOptions as $name => $value) {
157+
if (!isset($options[$name])) {
158+
$options[$name] = array($name, 'text', array('required' => false));
159+
}
160+
}
161+
162+
return $options;
163+
}
164+
145165
public function prePersist($object)
146166
{
147167
$defaults = array_filter($object->getDefaults());

CHANGELOG.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
Changelog
22
=========
33

4+
* **2014-03-29**: [Multilang] Added some options to support locale matching
5+
without separate routes per locale. See the new configuration options
6+
`match_implicit_locale` and `auto_locale_pattern`.
7+
8+
* **2014-03-29**: [PHPCR] The route provider can now load Routes from more than
9+
path in PHPCR. The configuration option `route_basepath` is renamed to
10+
`route_basepaths` and accepts a list of base paths. See the changelog of
11+
the SimpleCmsBundle as the main impact is on that side.
12+
13+
* **2014-03-26**: [ORM] Applied the cleanup for the PHPCR provider to the ORM
14+
provider now: If the route matched a pattern with a format extension, the
15+
format extension is no longer set as route a default.
16+
417
* **2014-03-25**: setParent() and getParent() are now deprecated.
518
Use setParentDocument() and getParentDocument() instead.
619
Moreover, you should now enable the ChildExtension from the CoreBundle.
720

821
* **2014-03-23**: When using PHPCR-ODM, routes can now be generated with their
922
uuid as route name as well, in addition to the repository path.
1023

11-
* **2013-11-28**: [BC BREAK] the alias attribute of the <template-by-class> is
12-
renamed to class in the bundle configuration.
24+
* **2013-11-28**: [BC BREAK for xml configuration] the alias attribute of the
25+
<template-by-class> is renamed to class in the bundle configuration.
1326

1427
1.1.0
1528
-----

DependencyInjection/CmfRoutingExtension.php

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,12 @@ private function setupDynamicRouter(array $config, ContainerBuilder $container,
9595
$container->setParameter($this->getAlias() . '.route_collection_limit', $config['route_collection_limit']);
9696

9797
$locales = false;
98-
if (isset($config['locales'])) {
98+
if (!empty($config['locales'])) {
9999
$locales = $config['locales'];
100100
$container->setParameter($this->getAlias() . '.dynamic.locales', $locales);
101+
$container->setParameter($this->getAlias() . '.dynamic.auto_locale_pattern', $config['auto_locale_pattern']);
101102
}
103+
$container->setParameter($this->getAlias() . '.dynamic.limit_candidates', $config['limit_candidates']);
102104

103105
$loader->load('routing-dynamic.xml');
104106

@@ -109,13 +111,13 @@ private function setupDynamicRouter(array $config, ContainerBuilder $container,
109111
}
110112

111113
if ($config['persistence']['phpcr']['enabled']) {
112-
$this->loadPhpcrProvider($config['persistence']['phpcr'], $loader, $container, $locales);
114+
$this->loadPhpcrProvider($config['persistence']['phpcr'], $loader, $container, $locales, $config['match_implicit_locale']);
113115
$hasProvider = true;
114116
$hasContentRepository = true;
115117
}
116118

117119
if ($config['persistence']['orm']['enabled']) {
118-
$this->loadOrmProvider($config['persistence']['orm'], $loader, $container);
120+
$this->loadOrmProvider($config['persistence']['orm'], $loader, $container, $locales, $config['match_implicit_locale']);
119121
$hasProvider = true;
120122
}
121123

@@ -226,22 +228,41 @@ private function setupDynamicRouter(array $config, ContainerBuilder $container,
226228
}
227229
}
228230

229-
public function loadPhpcrProvider($config, XmlFileLoader $loader, ContainerBuilder $container, $locales)
231+
public function loadPhpcrProvider($config, XmlFileLoader $loader, ContainerBuilder $container, $locales, $matchImplicitLocale)
230232
{
231233
$loader->load('provider-phpcr.xml');
232234

233235
$container->setParameter($this->getAlias() . '.backend_type_phpcr', true);
234236

235-
$container->setParameter($this->getAlias() . '.dynamic.persistence.phpcr.route_basepath', $config['route_basepath']);
236-
$container->setParameter($this->getAlias() . '.dynamic.persistence.phpcr.content_basepath', $config['content_basepath']);
237-
238-
$container->setParameter($this->getAlias() . '.dynamic.persistence.phpcr.manager_name', $config['manager_name']);
239-
240-
$container->setAlias($this->getAlias() . '.route_provider', $this->getAlias() . '.phpcr_route_provider');
241-
$container->setAlias($this->getAlias() . '.content_repository', $this->getAlias() . '.phpcr_content_repository');
237+
$container->setParameter(
238+
$this->getAlias() . '.dynamic.persistence.phpcr.route_basepaths',
239+
$config['route_basepaths']
240+
);
241+
$container->setParameter(
242+
$this->getAlias() . '.dynamic.persistence.phpcr.content_basepath',
243+
$config['content_basepath']
244+
);
245+
246+
$container->setParameter(
247+
$this->getAlias() . '.dynamic.persistence.phpcr.manager_name',
248+
$config['manager_name']
249+
);
250+
251+
$container->setAlias(
252+
$this->getAlias() . '.route_provider',
253+
$this->getAlias() . '.phpcr_route_provider'
254+
);
255+
$container->setAlias(
256+
$this->getAlias() . '.content_repository',
257+
$this->getAlias() . '.phpcr_content_repository'
258+
);
242259

243260
if (!$locales) {
244261
$container->removeDefinition($this->getAlias() . '.phpcrodm_route_locale_listener');
262+
} elseif (!$matchImplicitLocale) {
263+
// remove all but the prefixes configuration from the service definition.
264+
$definition = $container->getDefinition($this->getAlias() . '.phpcr_candidates_prefix');
265+
$definition->setArguments(array($definition->getArgument(0)));
245266
}
246267

247268
if ($config['use_sonata_admin']) {
@@ -256,14 +277,23 @@ public function loadSonataPhpcrAdmin($config, XmlFileLoader $loader, ContainerBu
256277
return;
257278
}
258279

280+
$basePath = empty($config['admin_basepath']) ? reset($config['route_basepaths']) : $config['admin_basepath'];
281+
$container->setParameter($this->getAlias() . '.dynamic.persistence.phpcr.admin_basepath', $basePath);
282+
259283
$loader->load('admin-phpcr.xml');
260284
}
261285

262-
public function loadOrmProvider($config, XmlFileLoader $loader, ContainerBuilder $container)
286+
public function loadOrmProvider($config, XmlFileLoader $loader, ContainerBuilder $container, $matchImplicitLocale)
263287
{
264288
$container->setParameter($this->getAlias() . '.dynamic.persistence.orm.manager_name', $config['manager_name']);
265289
$container->setParameter($this->getAlias() . '.backend_type_orm', true);
266290
$loader->load('provider-orm.xml');
291+
292+
if (!$matchImplicitLocale) {
293+
// remove the locales argument from the candidates
294+
$definition = $container->getDefinition($this->getAlias() . '.orm_candidates');
295+
$definition->setArguments(array());
296+
}
267297
}
268298

269299
/**

DependencyInjection/Configuration.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,18 @@ public function getConfigTreeBuilder()
7777
->arrayNode('phpcr')
7878
->addDefaultsIfNotSet()
7979
->canBeEnabled()
80+
->fixXmlConfig('route_basepath')
81+
->validate()
82+
->ifTrue(function ($v) { isset($v['route_basepath']) && isset($v['route_basepaths']); })
83+
->thenInvalid('Found values for both "route_basepath" and "route_basepaths", use "route_basepaths" instead.')
84+
->end()
8085
->children()
8186
->scalarNode('manager_name')->defaultNull()->end()
82-
->scalarNode('route_basepath')->defaultValue('/cms/routes')->end()
87+
->arrayNode('route_basepaths')
88+
->prototype('scalar')->end()
89+
->defaultValue(array('/cms/routes'))
90+
->end()
91+
->scalarNode('admin_basepath')->end()
8392
->scalarNode('content_basepath')->defaultValue('/cms/content')->end()
8493
->enumNode('use_sonata_admin')
8594
->beforeNormalization()
@@ -122,6 +131,9 @@ public function getConfigTreeBuilder()
122131
->arrayNode('locales')
123132
->prototype('scalar')->end()
124133
->end()
134+
->scalarNode('limit_candidates')->defaultValue(20)->end()
135+
->booleanNode('match_implicit_locale')->defaultValue(true)->end()
136+
->booleanNode('auto_locale_pattern')->defaultValue(false)->end()
125137
->end()
126138
->end()
127139
->end()

Doctrine/DoctrineProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ public function setManagerName($managerName)
7373
}
7474

7575
/**
76-
* Set the limit to apply when calling getRoutesByNames() with null.
77-
* Note that setting the limit to null means no limit applied.
76+
* Set the limit to apply when calling getAllRoutes().
77+
*
78+
* Setting the limit to null means no limit is applied.
7879
*
7980
* @param integer|null $routeCollectionLimit
8081
*/

0 commit comments

Comments
 (0)