-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the EasyAdminBundle. | ||
* | ||
* (c) Javier Eguiluz <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JavierEguiluz\Bundle\EasyAdminBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
class Configuration implements ConfigurationInterface | ||
{ | ||
public function getConfigTreeBuilder() | ||
{ | ||
$treeBuilder = new TreeBuilder(); | ||
$rootNode = $treeBuilder->root('easy_admin'); | ||
|
||
$rootNode | ||
->children() | ||
->scalarNode('site_name') | ||
->defaultValue('Easy Admin') | ||
->info('The name displayed as the title of the administration zone (e.g. comapny name, project name).') | ||
->end() | ||
->integerNode('list_max_results') | ||
->defaultValue('15') | ||
This comment has been minimized.
Sorry, something went wrong. |
||
->info('The maximum number of items to show on listing and search pages.') | ||
->end() | ||
->arrayNode('assets') | ||
->performNoDeepMerging() | ||
->addDefaultsIfNotSet() | ||
->children() | ||
->arrayNode('css') | ||
->prototype('scalar')->end() | ||
->end() | ||
->arrayNode('js') | ||
->prototype('scalar')->end() | ||
->end() | ||
->end() | ||
->end() | ||
->variableNode('list_actions') | ||
->info('The actions to show for each item of listing and search pages. Only "edit" and "show" options are avaialable.') | ||
->example(array('edit', 'show')) | ||
->end() | ||
->variableNode('entities') | ||
This comment has been minimized.
Sorry, something went wrong.
stof
|
||
->info('The list of entities to manage in the administration zone.') | ||
->end() | ||
->end(); | ||
|
||
return $treeBuilder; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the EasyAdminBundle. | ||
* | ||
* (c) Javier Eguiluz <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JavierEguiluz\Bundle\EasyAdminBundle\DependencyInjection; | ||
|
||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
class EasyAdminExtension extends Extension | ||
{ | ||
private $defaultConfigOptions = array( | ||
'site_name' => 'ACME', | ||
'list_max_results' => 15, | ||
'list_actions' => array('edit'), | ||
'entities' => array(), | ||
); | ||
|
||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
$configuration = new Configuration(); | ||
$config = $this->processConfiguration($configuration, $configs); | ||
|
||
$options = array_replace($this->defaultConfigOptions, $config); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
$options['entities'] = $this->processEntityConfiguration($options['entities']); | ||
|
||
$container->setParameter('easy_admin.config', $options); | ||
} | ||
|
||
protected function processEntityConfiguration($entitiesConfiguration) | ||
{ | ||
if (0 === count($entitiesConfiguration)) { | ||
return $entitiesConfiguration; | ||
} | ||
|
||
$entitiesConfigurationKeys = array_keys($entitiesConfiguration); | ||
if (is_integer($entitiesConfigurationKeys[0])) { | ||
return $this->processEntityConfigurationFromSimpleParameters($entitiesConfiguration); | ||
} | ||
|
||
return $this->processEntityConfigurationFromComplexParameters($entitiesConfiguration); | ||
} | ||
|
||
private function processEntityConfigurationFromSimpleParameters($config) | ||
{ | ||
$entities = array(); | ||
foreach ($config as $entityClass) { | ||
$parts = explode('\\', $entityClass); | ||
$entityName = array_pop($parts); | ||
|
||
$entities[$entityName] = array( | ||
'label' => $entityName, | ||
'name' => $entityName, | ||
'class' => $entityClass, | ||
); | ||
} | ||
|
||
return $entities; | ||
} | ||
|
||
private function processEntityConfigurationFromComplexParameters($config) | ||
{ | ||
$entities = array(); | ||
foreach ($config as $customEntityName => $entityConfiguration) { | ||
$parts = explode('\\', $entityConfiguration['class']); | ||
$realEntityName = array_pop($parts); | ||
|
||
// copy the original entity to not loose any of its configuration | ||
$entities[$realEntityName] = $config[$customEntityName]; | ||
|
||
// process the original configuration to use the format needed by the application | ||
$entities[$realEntityName]['label'] = $customEntityName; | ||
$entities[$realEntityName]['name'] = $realEntityName; | ||
$entities[$realEntityName]['class'] = $entityConfiguration['class']; | ||
} | ||
|
||
return $entities; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the EasyAdminBundle. | ||
* | ||
* (c) Javier Eguiluz <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JavierEguiluz\Bundle\EasyAdminBundle; | ||
|
||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
class EasyAdminBundle extends Bundle | ||
{ | ||
} |
the default value of an integer node should be an integer, not a string