Skip to content

Commit f08250a

Browse files
committed
First import
1 parent 26237f3 commit f08250a

27 files changed

+3040
-2
lines changed

Controller/AdminController.php

+474
Large diffs are not rendered by default.

DependencyInjection/Configuration.php

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the EasyAdminBundle.
5+
*
6+
* (c) Javier Eguiluz <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace JavierEguiluz\Bundle\EasyAdminBundle\DependencyInjection;
13+
14+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15+
use Symfony\Component\Config\Definition\ConfigurationInterface;
16+
17+
class Configuration implements ConfigurationInterface
18+
{
19+
public function getConfigTreeBuilder()
20+
{
21+
$treeBuilder = new TreeBuilder();
22+
$rootNode = $treeBuilder->root('easy_admin');
23+
24+
$rootNode
25+
->children()
26+
->scalarNode('site_name')
27+
->defaultValue('Easy Admin')
28+
->info('The name displayed as the title of the administration zone (e.g. comapny name, project name).')
29+
->end()
30+
->integerNode('list_max_results')
31+
->defaultValue('15')
32+
->info('The maximum number of items to show on listing and search pages.')
33+
->end()
34+
->arrayNode('assets')
35+
->performNoDeepMerging()
36+
->addDefaultsIfNotSet()
37+
->children()
38+
->arrayNode('css')
39+
->prototype('scalar')->end()
40+
->end()
41+
->arrayNode('js')
42+
->prototype('scalar')->end()
43+
->end()
44+
->end()
45+
->end()
46+
->variableNode('list_actions')
47+
->info('The actions to show for each item of listing and search pages. Only "edit" and "show" options are avaialable.')
48+
->example(array('edit', 'show'))
49+
->end()
50+
->variableNode('entities')
51+
->info('The list of entities to manage in the administration zone.')
52+
->end()
53+
->end();
54+
55+
return $treeBuilder;
56+
}
57+
}
+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the EasyAdminBundle.
5+
*
6+
* (c) Javier Eguiluz <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace JavierEguiluz\Bundle\EasyAdminBundle\DependencyInjection;
13+
14+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
17+
class EasyAdminExtension extends Extension
18+
{
19+
private $defaultConfigOptions = array(
20+
'site_name' => 'ACME',
21+
'list_max_results' => 15,
22+
'list_actions' => array('edit'),
23+
'entities' => array(),
24+
);
25+
26+
public function load(array $configs, ContainerBuilder $container)
27+
{
28+
$configuration = new Configuration();
29+
$config = $this->processConfiguration($configuration, $configs);
30+
31+
$options = array_replace($this->defaultConfigOptions, $config);
32+
$options['entities'] = $this->processEntityConfiguration($options['entities']);
33+
34+
$container->setParameter('easy_admin.config', $options);
35+
}
36+
37+
protected function processEntityConfiguration($entitiesConfiguration)
38+
{
39+
if (0 === count($entitiesConfiguration)) {
40+
return $entitiesConfiguration;
41+
}
42+
43+
$entitiesConfigurationKeys = array_keys($entitiesConfiguration);
44+
if (is_integer($entitiesConfigurationKeys[0])) {
45+
return $this->processEntityConfigurationFromSimpleParameters($entitiesConfiguration);
46+
}
47+
48+
return $this->processEntityConfigurationFromComplexParameters($entitiesConfiguration);
49+
}
50+
51+
private function processEntityConfigurationFromSimpleParameters($config)
52+
{
53+
$entities = array();
54+
foreach ($config as $entityClass) {
55+
$parts = explode('\\', $entityClass);
56+
$entityName = array_pop($parts);
57+
58+
$entities[$entityName] = array(
59+
'label' => $entityName,
60+
'name' => $entityName,
61+
'class' => $entityClass,
62+
);
63+
}
64+
65+
return $entities;
66+
}
67+
68+
private function processEntityConfigurationFromComplexParameters($config)
69+
{
70+
$entities = array();
71+
foreach ($config as $customEntityName => $entityConfiguration) {
72+
$parts = explode('\\', $entityConfiguration['class']);
73+
$realEntityName = array_pop($parts);
74+
75+
// copy the original entity to not loose any of its configuration
76+
$entities[$realEntityName] = $config[$customEntityName];
77+
78+
// process the original configuration to use the format needed by the application
79+
$entities[$realEntityName]['label'] = $customEntityName;
80+
$entities[$realEntityName]['name'] = $realEntityName;
81+
$entities[$realEntityName]['class'] = $entityConfiguration['class'];
82+
}
83+
84+
return $entities;
85+
}
86+
}

EasyAdminBundle.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the EasyAdminBundle.
5+
*
6+
* (c) Javier Eguiluz <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace JavierEguiluz\Bundle\EasyAdminBundle;
13+
14+
use Symfony\Component\HttpKernel\Bundle\Bundle;
15+
16+
class EasyAdminBundle extends Bundle
17+
{
18+
}

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
<img src="https://cloud.githubusercontent.com/assets/73419/5748433/476724ec-9c40-11e4-8f7a-5916c1212a22.png" alt="EasyAdmin" title="EasyAdmin" />
2-
31
EasyAdmin
42
=========
53

83.9 KB
Binary file not shown.
54.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)