Skip to content

Commit

Permalink
Merge pull request sonata-project#2215 from greg0ire/choose_route_bui…
Browse files Browse the repository at this point in the history
…lder_wisely

Choose route builder wisely
  • Loading branch information
rande committed Jul 3, 2014
2 parents cfc6c90 + 96b4a2c commit 92aaa66
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 20 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.idea
.DS_Store
build
phpunit.xml
Resources/doc/_build/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ public function applyDefaults(ContainerBuilder $container, $serviceId, array $at
'validator' => 'validator',
'security_handler' => 'sonata.admin.security.handler',
'menu_factory' => 'knp_menu.factory',
'route_builder' => 'sonata.admin.route.path_info',
'route_builder' => 'sonata.admin.route.path_info' .
(($manager_type == 'doctrine_phpcr') ? '_slashes' : ''),
'label_translator_strategy' => 'sonata.admin.label.strategy.native'
);

Expand Down
5 changes: 3 additions & 2 deletions Resources/doc/reference/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ router router
validator validator
security_handler sonata.admin.security.handler
menu_factory knp_menu.factory
route_builder sonata.admin.route.path_info
route_builder sonata.admin.route.path_info | sonata.admin.route.path_info_slashes
label_translator_strategy sonata.admin.label.strategy.form_component
========================= =============================================

Note: %manager-type% is to be replaced by the manager type (orm, doctrine_mongodb...)
Note: %manager-type% is to be replaced by the manager type (orm, doctrine_mongodb...),
and the default route_builder depends on it.

You have 2 ways of defining the dependencies inside ``services.xml``:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,26 @@ public function testProcessResultingConfig()
$this->assertContains('sonata_article_admin', $adminClasses['Sonata\AdminBundle\Tests\DependencyInjection\Article']);
$this->assertArrayHasKey('Sonata\AdminBundle\Tests\DependencyInjection\News', $adminClasses);
$this->assertContains('sonata_news_admin', $adminClasses['Sonata\AdminBundle\Tests\DependencyInjection\News']);
$this->assertSame(
'sonata.admin.route.path_info',
(string) current(array_filter(
$container->getDefinition('sonata_news_admin')->getMethodCalls(),
function ($element) {
return $element[0] == 'setRouteBuilder';
}
))[1][0],
'The news admin uses the orm, and should therefore use the path_info router.'
);
$this->assertSame(
'sonata.admin.route.path_info_slashes',
(string) current(array_filter(
$container->getDefinition('sonata_article_admin')->getMethodCalls(),
function ($element) {
return $element[0] == 'setRouteBuilder';
}
))[1][0],
'The article admin uses the odm, and should therefore use the path_info_slashes router.'
);
}

/**
Expand Down Expand Up @@ -199,21 +219,43 @@ private function getContainer()
$container
->register('form.factory')
->setClass('Symfony\Component\Form\FormFactoryInterface');
foreach (array(
'doctrine_phpcr' => 'PHPCR',
'orm' => 'ORM') as $key => $bundleSubstring) {
$container
->register(sprintf('sonata.admin.manager.%s', $key))
->setClass(sprintf(
'Sonata\Doctrine%sAdminBundle\Model\ModelManager',
$bundleSubstring
));
$container
->register(sprintf('sonata.admin.builder.%s_form', $key))
->setClass(sprintf(
'Sonata\Doctrine%sAdminBundle\Builder\FormContractor',
$bundleSubstring
));
$container
->register(sprintf('sonata.admin.builder.%s_show', $key))
->setClass(sprintf(
'Sonata\Doctrine%sAdminBundle\Builder\ShowBuilder',
$bundleSubstring
));
$container
->register(sprintf('sonata.admin.builder.%s_list', $key))
->setClass(sprintf(
'Sonata\Doctrine%sAdminBundle\Builder\ListBuilder',
$bundleSubstring
));
$container
->register(sprintf('sonata.admin.builder.%s_datagrid', $key))
->setClass(sprintf(
'Sonata\Doctrine%sAdminBundle\Builder\DatagridBuilder',
$bundleSubstring
));
}
$container
->register('sonata.admin.manager.orm')
->setClass('Sonata\DoctrineORMAdminBundle\Model\ModelManager');
$container
->register('sonata.admin.builder.orm_form')
->setClass('Sonata\DoctrineORMAdminBundle\Builder\FormContractor');
$container
->register('sonata.admin.builder.orm_show')
->setClass('Sonata\DoctrineORMAdminBundle\Builder\ShowBuilder');
$container
->register('sonata.admin.builder.orm_list')
->setClass('Sonata\DoctrineORMAdminBundle\Builder\ListBuilder');
$container
->register('sonata.admin.builder.orm_datagrid')
->setClass('Sonata\DoctrineORMAdminBundle\Builder\DatagridBuilder');
->register('sonata.admin.route.path_info_slashes')
->setClass('Sonata\DoctrinePHPCRAdminBundle\Route\PathInfoBuilderSlashes');
$container
->register('sonata.admin.route.cache')
->setClass('Sonata\AdminBundle\Route\RoutesCache');
Expand All @@ -239,7 +281,7 @@ private function getContainer()
->register('sonata_article_admin')
->setClass('Sonata\AdminBundle\Tests\DependencyInjection\MockAdmin')
->setArguments(array('', 'Sonata\AdminBundle\Tests\DependencyInjection\Article', 'SonataAdminBundle:CRUD'))
->addTag('sonata.admin', array('group' => 'sonata_group_one', 'manager_type' => 'orm'));
->addTag('sonata.admin', array('group' => 'sonata_group_one', 'manager_type' => 'doctrine_phpcr'));

return $container;
}
Expand Down

0 comments on commit 92aaa66

Please sign in to comment.