-
-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use SonataAdminBundle configuration to configure services (#1297)
- Loading branch information
Showing
4 changed files
with
92 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,15 +16,21 @@ | |
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; | ||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
|
||
/** | ||
* @author Thomas Rabaix <[email protected]> | ||
*/ | ||
class SonataMediaExtension extends Extension | ||
class SonataMediaExtension extends Extension implements PrependExtensionInterface | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $bundleConfigs; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
|
@@ -111,6 +117,24 @@ public function load(array $configs, ContainerBuilder $container) | |
|
||
if (isset($bundles['SonataAdminBundle'])) { | ||
$loader->load(sprintf('%s_admin.xml', $config['db_driver'])); | ||
|
||
$sonataAdminConfig = $this->bundleConfigs['SonataAdminBundle']; | ||
|
||
$sonataRoles = array(); | ||
if (isset($sonataAdminConfig['security']['role_admin'])) { | ||
$sonataRoles[] = $sonataAdminConfig['security']['role_admin']; | ||
} else { | ||
$sonataRoles[] = 'ROLE_ADMIN'; | ||
} | ||
|
||
if (isset($sonataAdminConfig['security']['role_super_admin'])) { | ||
$sonataRoles[] = $sonataAdminConfig['security']['role_super_admin']; | ||
} else { | ||
$sonataRoles[] = 'ROLE_SUPER_ADMIN'; | ||
} | ||
|
||
$container->getDefinition('sonata.media.security.superadmin_strategy') | ||
->replaceArgument(2, $sonataRoles); | ||
} | ||
|
||
$this->configureFilesystemAdapter($container, $config); | ||
|
@@ -551,6 +575,21 @@ public function configureClassesToCompile() | |
)); | ||
} | ||
|
||
/** | ||
* Allow an extension to prepend the extension configurations. | ||
* | ||
* @param ContainerBuilder $container | ||
*/ | ||
public function prepend(ContainerBuilder $container) | ||
{ | ||
$bundles = $container->getParameter('kernel.bundles'); | ||
|
||
// Store SonataAdminBundle configuration for later use | ||
if (isset($bundles['SonataAdminBundle'])) { | ||
$this->bundleConfigs['SonataAdminBundle'] = current($container->getExtensionConfig('sonata_admin')); | ||
} | ||
} | ||
|
||
/** | ||
* Checks if the classification of media is enabled. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters