Skip to content

Commit

Permalink
Trying to fix inexistent parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Mar 16, 2020
1 parent 45a0373 commit 54d5172
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/DependencyInjection/AbstractSonataAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ protected function fixTemplatesConfiguration(
];

$useIntlTemplates = $container->getParameter('sonata.admin.configuration.use_intl_templates');

if ($useIntlTemplates) {
$defaultConfig['templates']['types']['list'] = array_merge($defaultConfig['templates']['types']['list'], [
'date' => '@SonataAdmin/CRUD/Intl/list_date.html.twig',
Expand Down
12 changes: 7 additions & 5 deletions src/DependencyInjection/SonataAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ public function load(array $configs, ContainerBuilder $container)
$container->removeDefinition('sonata.admin.lock.extension');
}

$useIntlTemplates = $config['use_intl_templates'] || isset($bundles['SonataIntlBundle']);

$container->setParameter('sonata.admin.configuration.use_intl_templates', $useIntlTemplates);
$useIntlTemplates = $container->getParameter('sonata.admin.configuration.use_intl_templates');

if ($useIntlTemplates) {
if ('@SonataAdmin/CRUD/history_revision_timestamp.html.twig' === $config['templates']['history_revision_timestamp']) {
Expand Down Expand Up @@ -211,12 +209,16 @@ public function prepend(ContainerBuilder $container)
{
$bundles = $container->getParameter('kernel.bundles');

$configs = $container->getExtensionConfig($this->getAlias());
$config = $this->processConfiguration(new Configuration(), $configs);

$useIntlTemplates = $config['use_intl_templates'] || isset($bundles['SonataIntlBundle']);
$container->setParameter('sonata.admin.configuration.use_intl_templates', $useIntlTemplates);

if (!isset($bundles['JMSDiExtraBundle'])) {
return;
}

$configs = $container->getExtensionConfig($this->getAlias());
$config = $this->processConfiguration(new Configuration(), $configs);
if (!$config['options']['enable_jms_di_extra_autoregistration']) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function testTranslatorDisabled(): void
$container = $this->getContainer();
$container->removeAlias('translator');
$container->removeDefinition('translator');
$this->extension->prepend($container);
$this->extension->load([$this->config], $container);

$compilerPass = new AddDependencyCallsCompilerPass();
Expand All @@ -88,6 +89,7 @@ public function testTranslatorDisabled(): void
public function testProcessParsingFullValidConfig(): void
{
$container = $this->getContainer();
$this->extension->prepend($container);
$this->extension->load([$this->config], $container);

$compilerPass = new AddDependencyCallsCompilerPass();
Expand Down Expand Up @@ -152,6 +154,7 @@ public function testProcessParsingFullValidConfig(): void
public function testProcessResultingConfig(): void
{
$container = $this->getContainer();
$this->extension->prepend($container);
$this->extension->load([$this->config], $container);

$compilerPass = new AddDependencyCallsCompilerPass();
Expand Down Expand Up @@ -246,6 +249,7 @@ public function testProcessSortAdmins(): void
$config['options']['sort_admins'] = true;
unset($config['dashboard']['groups']);

$this->extension->prepend($container);
$this->extension->load([$config], $container);

$compilerPass = new AddDependencyCallsCompilerPass();
Expand All @@ -272,6 +276,7 @@ public function testProcessGroupNameAsParameter(): void
$container = $this->getContainer();
$container->setParameter('sonata.admin.parameter.groupname', 'resolved_group_name');

$this->extension->prepend($container);
$this->extension->load([$config], $container);

$compilerPass = new AddDependencyCallsCompilerPass();
Expand All @@ -288,6 +293,7 @@ public function testApplyTemplatesConfiguration(): void
{
$container = $this->getContainer();

$this->extension->prepend($container);
$this->extension->load([$this->getConfig()], $container);

$compilerPass = new AddDependencyCallsCompilerPass();
Expand Down Expand Up @@ -347,6 +353,7 @@ public function testApplyShowMosaicButtonConfiguration(): void
{
$container = $this->getContainer();

$this->extension->prepend($container);
$this->extension->load([$this->getConfig()], $container);

$compilerPass = new AddDependencyCallsCompilerPass();
Expand Down Expand Up @@ -386,6 +393,7 @@ public function testProcessMultipleOnTopOptions(): void
'route_params' => ['articleId' => 3],
];

$this->extension->prepend($container);
$this->extension->load([$config], $container);

$compilerPass = new AddDependencyCallsCompilerPass();
Expand Down Expand Up @@ -423,6 +431,7 @@ public function testProcessMultipleOnTopOptionsAdditionalGroup(): void
'roles' => ['ROLE_ONE'],
];

$this->extension->prepend($container);
$this->extension->load([$config], $container);

$compilerPass = new AddDependencyCallsCompilerPass();
Expand All @@ -440,6 +449,7 @@ public function testProcessMultipleOnTopOptionsInServiceDefinition(): void
$config = $this->config;
$config['dashboard']['groups'] = [];

$this->extension->prepend($container);
$this->extension->load([$config], $container);

$compilerPass = new AddDependencyCallsCompilerPass();
Expand All @@ -462,6 +472,7 @@ public function testProcessMultipleOnTopOptionsInServiceDefinition1(): void
$config = $this->config;
$config['dashboard']['groups'] = [];

$this->extension->prepend($container);
$this->extension->load([$config], $container);

$compilerPass = new AddDependencyCallsCompilerPass();
Expand All @@ -487,6 +498,7 @@ public function testProcessMultipleOnTopOptionsInServiceDefinition2(): void
$config = $this->config;
$config['dashboard']['groups'] = [];

$this->extension->prepend($container);
$this->extension->load([$config], $container);

$compilerPass = new AddDependencyCallsCompilerPass();
Expand Down Expand Up @@ -515,6 +527,7 @@ public function testProcessAbstractAdminServiceInServiceDefinition(): void
$config = $this->config;
$config['dashboard']['groups'] = [];

$this->extension->prepend($container);
$this->extension->load([$config], $container);

$compilerPass = new AddDependencyCallsCompilerPass();
Expand Down
13 changes: 10 additions & 3 deletions tests/DependencyInjection/Compiler/ExtensionCompilerPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public function setUp(): void
*/
public function testAdminExtensionLoad(): void
{
$this->extension->load([], $container = $this->getContainer());
$this->extension->prepend($container = $this->getContainer());
$this->extension->load([], $container);

$this->assertTrue($container->hasParameter($this->root.'.extension.map'));
$this->assertIsArray($extensionMap = $container->getParameter($this->root.'.extension.map'));
Expand All @@ -84,7 +85,8 @@ public function testAdminExtensionLoad(): void
*/
public function testFlattenEmptyExtensionConfiguration(): void
{
$this->extension->load([], $container = $this->getContainer());
$this->extension->prepend($container = $this->getContainer());
$this->extension->load([], $container);
$extensionMap = $container->getParameter($this->root.'.extension.map');

$method = new \ReflectionMethod(
Expand Down Expand Up @@ -116,7 +118,8 @@ public function testFlattenEmptyExtensionConfiguration(): void
public function testFlattenExtensionConfiguration(): void
{
$config = $this->getConfig();
$this->extension->load([$config], $container = $this->getContainer());
$this->extension->prepend($container = $this->getContainer());
$this->extension->load([$config], $container);
$extensionMap = $container->getParameter($this->root.'.extension.map');

$method = new \ReflectionMethod(
Expand Down Expand Up @@ -197,6 +200,7 @@ public function testProcessWithInvalidExtensionId(): void
];

$container = $this->getContainer();
$this->extension->prepend($container);
$this->extension->load([$config], $container);

$extensionsPass = new ExtensionCompilerPass();
Expand All @@ -220,6 +224,7 @@ public function testProcessWithInvalidAdminId(): void
];

$container = $this->getContainer();
$this->extension->prepend($container);
$this->extension->load([$config], $container);

$extensionsPass = new ExtensionCompilerPass();
Expand All @@ -235,6 +240,7 @@ public function testProcessWithInvalidAdminId(): void
public function testProcess(): void
{
$container = $this->getContainer();
$this->extension->prepend($container);
$this->extension->load([$this->config], $container);

$extensionsPass = new ExtensionCompilerPass();
Expand Down Expand Up @@ -297,6 +303,7 @@ public function testProcessThrowsExceptionIfTraitsAreNotAvailable(): void
];

$container = $this->getContainer();
$this->extension->prepend($container);
$this->extension->load([$config], $container);

$extensionsPass = new ExtensionCompilerPass();
Expand Down

0 comments on commit 54d5172

Please sign in to comment.