Skip to content

Commit

Permalink
Fix sonata-project#4292: don't overwrite DiExtraBundle default config…
Browse files Browse the repository at this point in the history
…uration

Preserve the default for the annotation_patterns option of
DiExtraBundle, otherwise annotations provided by DiExtraBundle itself
break if the project has no custom configuration for
annotation_patterns.
  • Loading branch information
andreasferber committed Feb 9, 2017
1 parent 165f8b3 commit 0c41636
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions DependencyInjection/SonataAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,41 @@ public function prepend(ContainerBuilder $container)
{
$bundles = $container->getParameter('kernel.bundles');

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

$sonataAdminPattern = 'Sonata\AdminBundle\Annotation';
$annotationPatternsConfigured = false;

$diExtraConfigs = $container->getExtensionConfig('jms_di_extra');
foreach ($diExtraConfigs as $diExtraConfig) {
if (isset($diExtraConfig['annotation_patterns'])) {
$annotationPatternsConfigured = true;
break;
}
}

if ($annotationPatternsConfigured) {
$container->prependExtensionConfig(
'jms_di_extra',
array(
'annotation_patterns' => array($sonataAdminPattern)
)
);
} else {
// get annotation_patterns default from DiExtraBundle configuration
$diExtraConfigDefinition = new \JMS\DiExtraBundle\DependencyInjection\Configuration();
// FIXME: this will break if DiExtraBundle adds any mandatory configuration
$diExtraConfig = $this->processConfiguration($diExtraConfigDefinition, array());

$annotationPatterns = $diExtraConfig['annotation_patterns'];
$annotationPatterns[] = $sonataAdminPattern;

$container->prependExtensionConfig(
'jms_di_extra',
array(
'annotation_patterns' => array(
'Sonata\AdminBundle\Annotation',
),
'annotation_patterns' => $annotationPatterns
)
);
}
Expand Down

0 comments on commit 0c41636

Please sign in to comment.