Skip to content

Commit

Permalink
Merge pull request #210 from symfony-cmf/cleanup-routing
Browse files Browse the repository at this point in the history
port features from simple cms into routing bundle to simplify things
  • Loading branch information
lsmith77 committed Apr 1, 2014
2 parents abbe0e1 + 2c9293e commit 98a70fe
Show file tree
Hide file tree
Showing 40 changed files with 1,887 additions and 534 deletions.
10 changes: 5 additions & 5 deletions Admin/RedirectRouteAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/


namespace Symfony\Cmf\Bundle\RoutingBundle\Admin;

use Sonata\AdminBundle\Datagrid\DatagridMapper;
Expand All @@ -31,7 +30,7 @@ class RedirectRouteAdmin extends Admin
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('id', 'text')
->addIdentifier('path', 'text')
;
}

Expand All @@ -44,14 +43,15 @@ protected function configureFormFields(FormMapper $formMapper)
->add('routeName', 'text', array('required' => false))
->add('uri', 'text', array('required' => false))
->add('routeTarget', 'doctrine_phpcr_odm_tree', array('choice_list' => array(), 'required' => false, 'root_node' => $this->routeRoot))
->end();
->end()
;
}

protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('name', 'doctrine_phpcr_nodename')
;
;
}

public function setRouteRoot($routeRoot)
Expand All @@ -69,6 +69,6 @@ public function toString($object)
return $object instanceof Route && $object->getId()
? $object->getId()
: $this->trans('link_add', array(), 'SonataAdminBundle')
;
;
}
}
36 changes: 28 additions & 8 deletions Admin/RouteAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,26 @@ protected function configureFormFields(FormMapper $formMapper)
array('choice_list' => array(), 'select_root_node' => true, 'root_node' => $this->routeRoot)
)
->add('name', 'text')
->add('addFormatPattern', null, array('required' => false, 'help' => 'form.help_add_format_pattern'))
->add('addTrailingSlash', null, array('required' => false, 'help' => 'form.help_add_trailing_slash'))
->end();

if (null === $this->getParentFieldDescription()) {
$formMapper
->with('form.group_general')
->add('variablePattern', 'text', array('required' => false))
->add('content', 'doctrine_phpcr_odm_tree', array('choice_list' => array(), 'required' => false, 'root_node' => $this->contentRoot))
->add('defaults', 'sonata_type_immutable_array', array('keys' => $this->configureFieldsForDefaults()))
->add('content', 'doctrine_phpcr_odm_tree', array('choice_list' => array(), 'required' => false, 'root_node' => $this->contentRoot))
->end()
->with('form.group_advanced')
->add('variablePattern', 'text', array('required' => false), array('help' => 'form.help_variable_pattern'))
->add('defaults', 'sonata_type_immutable_array', array('keys' => $this->configureFieldsForDefaults()))
->add('options', 'sonata_type_immutable_array', array('keys' => $this->configureFieldsForOptions()), array('help' => 'form.help_options'))
->end()
->end();
}
}

protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('name', 'doctrine_phpcr_string');
->add('name', 'doctrine_phpcr_nodename');
}

public function setRouteRoot($routeRoot)
Expand All @@ -110,7 +112,7 @@ public function getExportFormats()

protected function configureFieldsForDefaults()
{
$defaults = array(
$defaults = array(
'_controller' => array('_controller', 'text', array('required' => false)),
'_template' => array('_template', 'text', array('required' => false)),
'type' => array('type', 'cmf_routing_route_type', array(
Expand All @@ -125,7 +127,7 @@ protected function configureFieldsForDefaults()
$defaults[$name] = array($name, 'text', array('required' => false));
}
}

//parse variable pattern and add defaults for it - taken from routecompiler
/** @var $route Route */
$route = $this->subject;
Expand All @@ -142,6 +144,24 @@ protected function configureFieldsForDefaults()
return $defaults;
}

protected function configureFieldsForOptions()
{
$options = array(
array('add_locale_pattern', 'checkbox', array('required' => false, 'label' => 'form.label_add_locale_pattern', 'translation_domain' => $this->translationDomain)),
array('add_format_pattern', 'checkbox', array('required' => false, 'label' => 'form.label_add_format_pattern', 'translation_domain' => $this->translationDomain)),
array('add_trailing_slash', 'checkbox', array('required' => false, 'label' => 'form.label_add_trailing_slash', 'translation_domain' => $this->translationDomain)),
);

$dynamicOptions = $this->getSubject()->getOptions();
foreach ($dynamicOptions as $name => $value) {
if (!isset($options[$name])) {
$options[$name] = array($name, 'text', array('required' => false));
}
}

return $options;
}

public function prePersist($object)
{
$defaults = array_filter($object->getDefaults());
Expand Down
17 changes: 15 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
Changelog
=========

* **2014-03-29**: [Multilang] Added some options to support locale matching
without separate routes per locale. See the new configuration options
`match_implicit_locale` and `auto_locale_pattern`.

* **2014-03-29**: [PHPCR] The route provider can now load Routes from more than
path in PHPCR. The configuration option `route_basepath` is renamed to
`route_basepaths` and accepts a list of base paths. See the changelog of
the SimpleCmsBundle as the main impact is on that side.

* **2014-03-26**: [ORM] Applied the cleanup for the PHPCR provider to the ORM
provider now: If the route matched a pattern with a format extension, the
format extension is no longer set as route a default.

* **2014-03-25**: setParent() and getParent() are now deprecated.
Use setParentDocument() and getParentDocument() instead.
Moreover, you should now enable the ChildExtension from the CoreBundle.

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

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

1.1.0
-----
Expand Down
54 changes: 42 additions & 12 deletions DependencyInjection/CmfRoutingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ private function setupDynamicRouter(array $config, ContainerBuilder $container,
$container->setParameter($this->getAlias() . '.route_collection_limit', $config['route_collection_limit']);

$locales = false;
if (isset($config['locales'])) {
if (!empty($config['locales'])) {
$locales = $config['locales'];
$container->setParameter($this->getAlias() . '.dynamic.locales', $locales);
$container->setParameter($this->getAlias() . '.dynamic.auto_locale_pattern', $config['auto_locale_pattern']);
}
$container->setParameter($this->getAlias() . '.dynamic.limit_candidates', $config['limit_candidates']);

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

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

if ($config['persistence']['phpcr']['enabled']) {
$this->loadPhpcrProvider($config['persistence']['phpcr'], $loader, $container, $locales);
$this->loadPhpcrProvider($config['persistence']['phpcr'], $loader, $container, $locales, $config['match_implicit_locale']);
$hasProvider = true;
$hasContentRepository = true;
}

if ($config['persistence']['orm']['enabled']) {
$this->loadOrmProvider($config['persistence']['orm'], $loader, $container);
$this->loadOrmProvider($config['persistence']['orm'], $loader, $container, $locales, $config['match_implicit_locale']);
$hasProvider = true;
}

Expand Down Expand Up @@ -226,22 +228,41 @@ private function setupDynamicRouter(array $config, ContainerBuilder $container,
}
}

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

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

$container->setParameter($this->getAlias() . '.dynamic.persistence.phpcr.route_basepath', $config['route_basepath']);
$container->setParameter($this->getAlias() . '.dynamic.persistence.phpcr.content_basepath', $config['content_basepath']);

$container->setParameter($this->getAlias() . '.dynamic.persistence.phpcr.manager_name', $config['manager_name']);

$container->setAlias($this->getAlias() . '.route_provider', $this->getAlias() . '.phpcr_route_provider');
$container->setAlias($this->getAlias() . '.content_repository', $this->getAlias() . '.phpcr_content_repository');
$container->setParameter(
$this->getAlias() . '.dynamic.persistence.phpcr.route_basepaths',
$config['route_basepaths']
);
$container->setParameter(
$this->getAlias() . '.dynamic.persistence.phpcr.content_basepath',
$config['content_basepath']
);

$container->setParameter(
$this->getAlias() . '.dynamic.persistence.phpcr.manager_name',
$config['manager_name']
);

$container->setAlias(
$this->getAlias() . '.route_provider',
$this->getAlias() . '.phpcr_route_provider'
);
$container->setAlias(
$this->getAlias() . '.content_repository',
$this->getAlias() . '.phpcr_content_repository'
);

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

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

$basePath = empty($config['admin_basepath']) ? reset($config['route_basepaths']) : $config['admin_basepath'];
$container->setParameter($this->getAlias() . '.dynamic.persistence.phpcr.admin_basepath', $basePath);

$loader->load('admin-phpcr.xml');
}

public function loadOrmProvider($config, XmlFileLoader $loader, ContainerBuilder $container)
public function loadOrmProvider($config, XmlFileLoader $loader, ContainerBuilder $container, $matchImplicitLocale)
{
$container->setParameter($this->getAlias() . '.dynamic.persistence.orm.manager_name', $config['manager_name']);
$container->setParameter($this->getAlias() . '.backend_type_orm', true);
$loader->load('provider-orm.xml');

if (!$matchImplicitLocale) {
// remove the locales argument from the candidates
$definition = $container->getDefinition($this->getAlias() . '.orm_candidates');
$definition->setArguments(array());
}
}

/**
Expand Down
14 changes: 13 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,18 @@ public function getConfigTreeBuilder()
->arrayNode('phpcr')
->addDefaultsIfNotSet()
->canBeEnabled()
->fixXmlConfig('route_basepath')
->validate()
->ifTrue(function ($v) { isset($v['route_basepath']) && isset($v['route_basepaths']); })
->thenInvalid('Found values for both "route_basepath" and "route_basepaths", use "route_basepaths" instead.')
->end()
->children()
->scalarNode('manager_name')->defaultNull()->end()
->scalarNode('route_basepath')->defaultValue('/cms/routes')->end()
->arrayNode('route_basepaths')
->prototype('scalar')->end()
->defaultValue(array('/cms/routes'))
->end()
->scalarNode('admin_basepath')->end()
->scalarNode('content_basepath')->defaultValue('/cms/content')->end()
->enumNode('use_sonata_admin')
->beforeNormalization()
Expand Down Expand Up @@ -122,6 +131,9 @@ public function getConfigTreeBuilder()
->arrayNode('locales')
->prototype('scalar')->end()
->end()
->scalarNode('limit_candidates')->defaultValue(20)->end()
->booleanNode('match_implicit_locale')->defaultValue(true)->end()
->booleanNode('auto_locale_pattern')->defaultValue(false)->end()
->end()
->end()
->end()
Expand Down
5 changes: 3 additions & 2 deletions Doctrine/DoctrineProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ public function setManagerName($managerName)
}

/**
* Set the limit to apply when calling getRoutesByNames() with null.
* Note that setting the limit to null means no limit applied.
* Set the limit to apply when calling getAllRoutes().
*
* Setting the limit to null means no limit is applied.
*
* @param integer|null $routeCollectionLimit
*/
Expand Down
Loading

0 comments on commit 98a70fe

Please sign in to comment.