Skip to content

Commit d9ece63

Browse files
committed
Merge pull request #98 from symfony-cmf/cleanup-routing
refactor common features into RoutingBundle
2 parents c3384bf + 9ae1897 commit d9ece63

36 files changed

+1087
-1244
lines changed

Admin/PageAdmin.php

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

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

15-
use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin;
1614
use Sonata\AdminBundle\Form\FormMapper;
1715
use Sonata\AdminBundle\Datagrid\DatagridMapper;
1816
use Sonata\AdminBundle\Datagrid\ListMapper;
17+
use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin;
18+
use Symfony\Cmf\Bundle\RoutingBundle\Admin\RouteAdmin;
1919
use Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page;
20-
use Symfony\Cmf\Bundle\SimpleCmsBundle\Model\Page as ModelPage;
20+
use Symfony\Component\Form\FormBuilder;
2121

22-
class PageAdmin extends Admin
22+
class PageAdmin extends RouteAdmin
2323
{
2424
protected $translationDomain = 'CmfSimpleCmsBundle';
2525

@@ -37,32 +37,41 @@ protected function configureListFields(ListMapper $listMapper)
3737
{
3838
$listMapper
3939
->addIdentifier('path', 'text')
40-
->add('title', 'text')
40+
->addIdentifier('title', 'text')
4141
->add('label', 'text')
4242
->add('name', 'text')
4343
->add('createDate', 'date')
44-
->add('publishStartDate', 'date')
45-
->add('publishEndDate', 'date')
4644
;
4745
}
4846

4947
protected function configureFormFields(FormMapper $formMapper)
5048
{
49+
parent::configureFormFields($formMapper);
50+
51+
$formMapper->remove('content');
52+
53+
// remap to routeOptions
54+
$formMapper->remove('options');
55+
5156
$formMapper
52-
->with('form.group_general')
53-
->add(
54-
'parent',
55-
'doctrine_phpcr_odm_tree',
56-
array('choice_list' => array(), 'select_root_node' => true, 'root_node' => $this->getRootPath())
57-
)
58-
->add('name', 'text')
59-
->add('label', null, array('required' => false))
60-
->add('title')
61-
->add('createDate')
62-
->add('addFormatPattern', null, array('required' => false, 'help' => 'form.help_add_format_pattern'))
63-
->add('addTrailingSlash', null, array('required' => false, 'help' => 'form.help_add_trailing_slash'))
64-
->add('addLocalePattern', null, array('required' => false, 'help' => 'form.help_add_locale_pattern'))
65-
->add('body', 'textarea')
57+
->with('form.group_general', array(
58+
'translation_domain' => 'CmfSimpleCmsBundle',
59+
))
60+
->add('label', null, array('required' => false))
61+
->add('title')
62+
->add('body', 'textarea')
63+
->add('createDate')
64+
->end()
65+
->with('form.group_advanced', array(
66+
'translation_domain' => 'CmfRoutingBundle',
67+
))
68+
->add(
69+
'routeOptions',
70+
'sonata_type_immutable_array',
71+
array('keys' => $this->configureFieldsForOptions($this->getSubject()->getRouteOptions()), 'label' => 'form.label_options'),
72+
array('help' => 'form.help_options')
73+
)
74+
->end()
6675
;
6776
}
6877

@@ -98,7 +107,7 @@ public function preUpdate($object)
98107
*/
99108
protected function ensureOrderByDate($page)
100109
{
101-
$items = $page->getParent()->getChildren();
110+
$items = $page->getParentDocument()->getChildren();
102111

103112
$itemsByDate = array();
104113
/** @var $item Page */
@@ -135,7 +144,7 @@ protected function ensureOrderByDate($page)
135144

136145
public function toString($object)
137146
{
138-
return $object instanceof ModelPage && $object->getTitle()
147+
return $object instanceof Page && $object->getTitle()
139148
? $object->getTitle()
140149
: $this->trans('link_add', array(), 'SonataAdminBundle')
141150
;

CHANGELOG.md

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

4+
* **2014-04-01**: Refactored the RoutingBundle to provide all routing
5+
features needed by SimpleCmsBundle.
6+
* If you where only using the SimpleCmsBundle you now need to activate
7+
the dynamic router. SimpleCmsBundle automatically does this for you.
8+
* The configuration for document to route/template now all happens under
9+
cmf_routing.dynamic and the route enhancers also apply to simplecms Pages.
10+
You can configure additional base paths where to look for routes in the
11+
cmf_routing.persistence.phpcr.base_routepaths field.
12+
* The configuration for locales is not needed anymore. Configuring it on the
13+
cmf_routing is enough.
14+
* The options for the format pattern, trailing slash and locale pattern are
15+
now moved into the route "options" and the Page Document now takes an
16+
array of options in the constructor instead of boolean flags.
17+
418
* **2013-11-14**: The Page now supports the menu options that make sense for a
519
page: display, displayChildren, attributes, children|link|labelAttributes.
620
Note that those only affect the menu rendering, not anything else.

CmfSimpleCmsBundle.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public function build(ContainerBuilder $container)
3030
$container->addCompilerPass(
3131
DoctrinePhpcrMappingsPass::createXmlMappingDriver(
3232
array(
33-
realpath(__DIR__ . '/Resources/config/doctrine-model') => 'Symfony\Cmf\Bundle\SimpleCmsBundle\Model',
3433
realpath(__DIR__ . '/Resources/config/doctrine-phpcr') => 'Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr',
3534
),
3635
array('cmf_simple_cms.persistence.phpcr.manager_name')

DependencyInjection/CmfSimpleCmsExtension.php

Lines changed: 26 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,32 @@ class CmfSimpleCmsExtension extends Extension implements PrependExtensionInterfa
3232
*/
3333
public function prepend(ContainerBuilder $container)
3434
{
35-
$prependConfig = array('persistence' => array('phpcr' => (array('enabled' => true))));
36-
$container->prependExtensionConfig('cmf_menu', $prependConfig);
37-
$prependConfig = array('dynamic' => $prependConfig);
35+
// process the configuration of CmfCoreExtension
36+
$configs = $container->getExtensionConfig($this->getAlias());
37+
$parameterBag = $container->getParameterBag();
38+
$configs = $parameterBag->resolveValue($configs);
39+
$config = $this->processConfiguration(new Configuration(), $configs);
40+
41+
if (empty($config['persistence']['phpcr']['enabled'])) {
42+
return;
43+
}
44+
45+
$prependConfig = array(
46+
'chain' => array(
47+
'routers_by_id' => array(
48+
'router.default' => 0,
49+
'cmf_routing.dynamic_router' => -100,
50+
)
51+
),
52+
'dynamic' => array(
53+
'enabled' => true,
54+
)
55+
);
56+
if (isset($config['persistence']['phpcr']['basepath'])
57+
&& '/cms/simple' != $config['persistence']['phpcr']['basepath']
58+
) {
59+
$prependConfig['dynamic']['persistence']['phpcr']['route_basepaths'] = array($config['persistence']['phpcr']['basepath']);
60+
}
3861
$container->prependExtensionConfig('cmf_routing', $prependConfig);
3962
}
4063

@@ -43,101 +66,20 @@ public function load(array $configs, ContainerBuilder $container)
4366
$config = $this->processConfiguration(new Configuration(), $configs);
4467
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
4568

46-
$this->loadRouting($config['routing'], $loader, $container);
47-
4869
if ($config['persistence']['phpcr']) {
4970
$this->loadPhpcr($config['persistence']['phpcr'], $loader, $container);
50-
$locales = isset($config['multilang']['locales']) ? $config['multilang']['locales'] : false;
51-
$this->loadPhpcrRouting($config, $loader, $container, $locales);
5271

5372
if ($config['use_menu']) {
5473
$this->loadPhpcrMenu($config, $loader, $container);
5574
}
5675
}
5776
}
5877

59-
protected function loadRouting($config, XmlFileLoader $loader, ContainerBuilder $container)
60-
{
61-
$container->setParameter($this->getAlias() . '.uri_filter_regexp', $config['uri_filter_regexp']);
62-
63-
$loader->load('routing.xml');
64-
65-
$dynamic = $container->getDefinition($this->getAlias().'.dynamic_router');
66-
67-
if (!empty($config['generic_controller'])) {
68-
$definition = new DefinitionDecorator('cmf_routing.enhancer.explicit_template');
69-
$definition->replaceArgument(2, $config['generic_controller']);
70-
$container->setDefinition(
71-
$this->getAlias() . '.enhancer.explicit_template',
72-
$definition
73-
);
74-
$dynamic->addMethodCall('addRouteEnhancer', array(
75-
new Reference($this->getAlias() . '.enhancer.explicit_template')
76-
));
77-
}
78-
79-
if (!empty($config['controllers_by_type'])) {
80-
$definition = new DefinitionDecorator('cmf_routing.enhancer.controllers_by_type');
81-
$definition->replaceArgument(2, $config['controllers_by_type']);
82-
$container->setDefinition(
83-
$this->getAlias() . '.enhancer.controllers_by_type',
84-
$definition
85-
);
86-
$dynamic->addMethodCall('addRouteEnhancer', array(
87-
new Reference($this->getAlias() . '.enhancer.controllers_by_type')
88-
));
89-
}
90-
91-
if (!empty($config['controllers_by_class'])) {
92-
$definition = new DefinitionDecorator('cmf_routing.enhancer.controllers_by_class');
93-
$definition->replaceArgument(2, $config['controllers_by_class']);
94-
$container->setDefinition(
95-
$this->getAlias() . '.enhancer.controllers_by_class',
96-
$definition
97-
);
98-
$dynamic->addMethodCall('addRouteEnhancer', array(
99-
new Reference($this->getAlias() . '.enhancer.controllers_by_class')
100-
));
101-
}
102-
103-
if (!empty($config['generic_controller']) && !empty($config['templates_by_class'])) {
104-
$controllerForTemplates = array();
105-
foreach ($config['templates_by_class'] as $key => $value) {
106-
$controllerForTemplates[$key] = $config['generic_controller'];
107-
}
108-
109-
$definition = new DefinitionDecorator('cmf_routing.enhancer.controller_for_templates_by_class');
110-
$definition->replaceArgument(2, $controllerForTemplates);
111-
112-
$container->setDefinition(
113-
$this->getAlias() . '.enhancer.controller_for_templates_by_class',
114-
$definition
115-
);
116-
117-
$definition = new DefinitionDecorator('cmf_routing.enhancer.templates_by_class');
118-
$definition->replaceArgument(2, $config['templates_by_class']);
119-
120-
$container->setDefinition(
121-
$this->getAlias() . '.enhancer.templates_by_class',
122-
$definition
123-
);
124-
125-
$dynamic->addMethodCall('addRouteEnhancer', array(
126-
new Reference($this->getAlias() . '.enhancer.controller_for_templates_by_class')
127-
));
128-
$dynamic->addMethodCall('addRouteEnhancer', array(
129-
new Reference($this->getAlias() . '.enhancer.templates_by_class')
130-
));
131-
}
132-
}
133-
13478
protected function loadPhpcr($config, XmlFileLoader $loader, ContainerBuilder $container)
13579
{
13680
$loader->load('services-phpcr.xml');
137-
// migrator is only for PHPCR
13881
$loader->load('migrator-phpcr.xml');
13982

140-
// save some characters
14183
$prefix = $this->getAlias() . '.persistence.phpcr';
14284

14385
$container->setParameter($prefix . '.basepath', $config['basepath']);
@@ -155,24 +97,6 @@ protected function loadPhpcr($config, XmlFileLoader $loader, ContainerBuilder $c
15597
$container->setParameter($prefix . '.document.class', $config['document_class']);
15698
}
15799

158-
protected function loadPhpcrRouting($config, XmlFileLoader $loader, ContainerBuilder $container, $locales)
159-
{
160-
$loader->load('routing-phpcr.xml');
161-
$prefix = $this->getAlias() . '.persistence.phpcr';
162-
163-
$routeProvider = $container->getDefinition($prefix.'.route_provider');
164-
$routeProvider->replaceArgument(0, new Reference($config['persistence']['phpcr']['manager_registry']));
165-
if (!empty($locales)) {
166-
$routeProvider->addMethodCall('setLocales', array($locales));
167-
}
168-
$container->setAlias($this->getAlias() . '.route_provider', $prefix.'.route_provider');
169-
170-
$generator = $container->getDefinition($this->getAlias().'.generator');
171-
$generator->addMethodCall('setContentRepository', array(
172-
new Reference($config['routing']['content_repository_id'])
173-
));
174-
}
175-
176100
protected function loadPhpcrMenu($config, XmlFileLoader $loader, ContainerBuilder $container)
177101
{
178102
$bundles = $container->getParameter('kernel.bundles');

DependencyInjection/Configuration.php

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,37 +58,17 @@ public function getConfigTreeBuilder()
5858
->end()
5959

6060
->arrayNode('routing')
61-
->fixXmlConfig('controller_by_type', 'controllers_by_type')
62-
->fixXmlConfig('controller_by_class', 'controllers_by_class')
63-
->fixXmlConfig('template_by_class', 'templates_by_class')
64-
->addDefaultsIfNotSet()
65-
->children()
66-
->scalarNode('generic_controller')->defaultValue('cmf_content.controller:indexAction')->end()
67-
->scalarNode('content_repository_id')->defaultValue('cmf_routing.content_repository')->end()
68-
->scalarNode('uri_filter_regexp')->defaultValue('')->end()
69-
->arrayNode('controllers_by_type')
70-
->useAttributeAsKey('type')
71-
->prototype('scalar')->end()
72-
->end()
73-
->arrayNode('controllers_by_class')
74-
->useAttributeAsKey('alias')
75-
->prototype('scalar')->end()
76-
->end()
77-
->arrayNode('templates_by_class')
78-
->useAttributeAsKey('alias')
79-
->prototype('scalar')->end()
80-
->end()
61+
->info('removed')
62+
->beforeNormalization()
63+
->ifArray()
64+
->thenInvalid('The SimpleCmsBundle routing configuration has moved to cmf_routing.dynamic')
8165
->end()
8266
->end()
83-
8467
->arrayNode('multilang')
85-
->fixXmlConfig('locale')
86-
->children()
87-
->arrayNode('locales')
88-
->isRequired()
89-
->requiresAtLeastOneElement()
90-
->prototype('scalar')->end()
91-
->end()
68+
->info('removed')
69+
->beforeNormalization()
70+
->ifArray()
71+
->thenInvalid('The SimpleCmsBundle locale configuration is not needed anymore')
9272
->end()
9373
->end()
9474
->end()

Doctrine/Phpcr/MultilangRedirectRoute.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)