Skip to content

Commit

Permalink
Stop using SonataAdmin config in doctrineORMAdmin
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Apr 27, 2021
1 parent 7493cff commit 5e618d3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* NEXT_MAJOR: Remove the "since" part of the internal annotation.
*
* @internal since sonata-project/admin-bundle version 4.0
*
* @final since sonata-project/doctrine-orm-admin-bundle 3.24
*
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
Expand Down
4 changes: 4 additions & 0 deletions src/DependencyInjection/Compiler/AddGuesserCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
use Symfony\Component\DependencyInjection\Reference;

/**
* NEXT_MAJOR: Remove the "since" part of the internal annotation.
*
* @internal since sonata-project/admin-bundle version 4.0
*
* @final since sonata-project/doctrine-orm-admin-bundle 3.24
*
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
Expand Down
35 changes: 18 additions & 17 deletions src/DependencyInjection/Compiler/AddTemplatesCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
use Symfony\Component\DependencyInjection\Definition;

/**
* NEXT_MAJOR: Remove the "since" part of the internal annotation.
*
* @internal since sonata-project/admin-bundle version 4.0
*
* @final since sonata-project/doctrine-orm-admin-bundle 3.24
*
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
Expand All @@ -26,7 +30,6 @@ class AddTemplatesCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$overwrite = $container->getParameter('sonata.admin.configuration.admin_services');
$templates = $container->getParameter('sonata_doctrine_orm_admin.templates');

foreach ($container->findTaggedServiceIds('sonata.admin') as $id => $attributes) {
Expand All @@ -36,32 +39,30 @@ public function process(ContainerBuilder $container)

$definition = $container->getDefinition($id);

if (!$definition->hasMethodCall('setFormTheme')) {
$definition->addMethodCall('setFormTheme', [$templates['form']]);
}

if (isset($overwrite[$id]['templates']['form'])) {
$this->mergeMethodCall($definition, 'setFormTheme', $overwrite[$id]['templates']['form']);
}
// NEXT_MAJOR: Remove this line and uncomment the following
$this->mergeMethodCall($definition, 'setFormTheme', $templates['form']);
// $this->mergeMethodCall($definition, 'setFormTheme', ['@SonataDoctrineORMAdmin/Form/form_admin_fields.html.twig']);

if (!$definition->hasMethodCall('setFilterTheme')) {
$definition->addMethodCall('setFilterTheme', [$templates['filter']]);
}

if (isset($overwrite[$id]['templates']['filter'])) {
$this->mergeMethodCall($definition, 'setFilterTheme', $overwrite[$id]['templates']['filter']);
}
// NEXT_MAJOR: Remove this line and uncomment the following
$this->mergeMethodCall($definition, 'setFilterTheme', $templates['filter']);
// $this->mergeMethodCall($definition, 'setFilterTheme', ['@SonataDoctrineORMAdmin/Form/filter_admin_fields.html.twig']);
}
}

/**
* @param string $name
* @param mixed $value
* @param string $name
* @param array<mixed> $value
*
* @return void
*/
public function mergeMethodCall(Definition $definition, $name, $value)
{
if (!$definition->hasMethodCall($name)) {
$definition->addMethodCall($name, [$value]);

return;
}

$methodCalls = $definition->getMethodCalls();

foreach ($methodCalls as &$calls) {
Expand Down
4 changes: 4 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,15 @@ public function getConfigTreeBuilder()
->arrayNode('templates')
->addDefaultsIfNotSet()
->children()
// NEXT_MAJOR: Remove this option.
->arrayNode('form')
->setDeprecated('The "%node%" option is deprecated since sonata-project/admin-bundle 3.x.')
->prototype('scalar')->end()
->defaultValue(['@SonataDoctrineORMAdmin/Form/form_admin_fields.html.twig'])
->end()
// NEXT_MAJOR: Remove this option.
->arrayNode('filter')
->setDeprecated('The "%node%" option is deprecated since sonata-project/admin-bundle 3.x.')
->prototype('scalar')->end()
->defaultValue(['@SonataDoctrineORMAdmin/Form/filter_admin_fields.html.twig'])
->end()
Expand Down

0 comments on commit 5e618d3

Please sign in to comment.