Skip to content

Commit

Permalink
Introduced a new "design" global option
Browse files Browse the repository at this point in the history
  • Loading branch information
javiereguiluz committed Mar 31, 2015
1 parent 06e1c63 commit bb2a957
Show file tree
Hide file tree
Showing 102 changed files with 1,045 additions and 623 deletions.
214 changes: 165 additions & 49 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace JavierEguiluz\Bundle\EasyAdminBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

Expand All @@ -21,9 +22,20 @@ public function getConfigTreeBuilder()
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('easy_admin');

$this->addDeprecationsSection($rootNode);
$this->addGlobalOptionsSection($rootNode);
$this->addDesignSection($rootNode);
$this->addViewsSection($rootNode);
$this->addEntitiesSection($rootNode);

return $treeBuilder;
}

private function addDeprecationsSection(ArrayNodeDefinition $rootNode)
{
$rootNode
// 'list_actions' and 'max_results' global options are deprecated since 1.0.8
// and they are replaced by 'list -> 'actions' and 'list -> max_results' options
// 'list_max_results' global option was deprecated in 1.0.8
// and replaced by 'list -> max_results'
->beforeNormalization()
->ifTrue(function ($v) { return isset($v['list_max_results']); })
->then(function ($v) {
Expand All @@ -42,6 +54,8 @@ public function getConfigTreeBuilder()
})
->end()

// 'list_actions' global option was deprecated in 1.0.8
// and replaced by 'list -> actions'
->beforeNormalization()
->ifTrue(function ($v) { return isset($v['list_actions']); })
->then(function ($v) {
Expand All @@ -56,20 +70,158 @@ public function getConfigTreeBuilder()
})
->end()

// make sure the new 'design' global option exists to simplify
// updating the deprecated 'assets -> css' and 'assets -> js' options
->beforeNormalization()
->always()
->then(function ($v) {
if (!isset($v['design'])) {
$v['design'] = array('assets' => array());
}

return $v;
})
->end()

// 'assets -> css' global option was deprecated in 1.1.0
// and replaced by 'design -> assets -> css'
->beforeNormalization()
->ifTrue(function ($v) { return isset($v['assets']['css']); })
->then(function ($v) {
// if the new option is defined, don't override it with the legacy option
if (!isset($v['design']['assets']['css'])) {
$v['design']['assets']['css'] = $v['assets']['css'];
}

unset($v['assets']['css']);

return $v;
})
->end()

// 'assets -> js' global option was deprecated in 1.1.0
// and replaced by 'design -> assets -> js'
->beforeNormalization()
->ifTrue(function ($v) { return isset($v['assets']['js']); })
->then(function ($v) {
// if the new option is defined, don't override it with the legacy option
if (!isset($v['design']['assets']['js'])) {
$v['design']['assets']['js'] = $v['assets']['js'];
}

unset($v['assets']['js']);

return $v;
})
->end()

// after updating 'assets -> css' and 'assets -> js' deprecated options,
// remove the parent 'assets' deprecated option if it's defined
->beforeNormalization()
->always()
->then(function ($v) {
if (isset($v['assets'])) {
unset($v['assets']);
}

return $v;
})
->end()

->children()
->variableNode('list_actions')
->info('DEPRECATED: use the "actions" option of the "list" view.')
->end()

->integerNode('list_max_results')
->info('DEPRECATED: use "max_results" option under the "list" global key.')
->end()

->arrayNode('assets')
->performNoDeepMerging()
->children()
->arrayNode('css')
->info('DEPRECATED: use the "design -> assets -> css" option.')
->end()
->arrayNode('js')
->info('DEPRECATED: use the "design -> assets -> js" option.')
->end()
->end()
->end()
->end()
;
}

private function addGlobalOptionsSection(ArrayNodeDefinition $rootNode)
{
$rootNode
->children()
->scalarNode('site_name')
->defaultValue('Easy Admin')
->info('The name displayed as the title of the administration zone (e.g. company name, project name).')
->end()

->variableNode('list_actions')
->info('DEPRECATED: use the "actions" option of the "list" view.')
->arrayNode('formats')
->performNoDeepMerging()
->addDefaultsIfNotSet()
->children()
->scalarNode('date')
->defaultValue('Y-m-d')
->info('The PHP date format applied to "date" field types.')
->example('d/m/Y (see http://php.net/manual/en/function.date.php)')
->end()
->scalarNode('time')
->defaultValue('H:i:s')
->info('The PHP time format applied to "time" field types.')
->example('h:i a (see http://php.net/date)')
->end()
->scalarNode('datetime')
->defaultValue('F j, Y H:i')
->info('The PHP date/time format applied to "datetime" field types.')
->example('l, F jS Y / h:i (see http://php.net/date)')
->end()
->scalarNode('number')
->info('The sprintf-compatible format applied to numeric values.')
->example('%.2d (see http://php.net/sprintf)')
->end()
->end()
->end()
->end()
;
}

->integerNode('list_max_results')
->info('DEPRECATED: use "max_results" option under the "list" global key.')
private function addDesignSection(ArrayNodeDefinition $rootNode)
{
$rootNode
->children()
->arrayNode('design')
->performNoDeepMerging()
->addDefaultsIfNotSet()
->children()
->arrayNode('assets')
->performNoDeepMerging()
->addDefaultsIfNotSet()
->children()
->arrayNode('css')
->prototype('scalar')->end()
->info('The array of CSS assets to load in all backend pages.')
->end()
->arrayNode('js')
->prototype('scalar')->end()
->info('The array of JavaScript assets to load in all backend pages.')
->end()
->end()
->end()
->end()
->end()
->end()
;
}

private function addViewsSection(ArrayNodeDefinition $rootNode)
{
$rootNode
->children()
->arrayNode('list')
->addDefaultsIfNotSet()
->children()
Expand Down Expand Up @@ -113,55 +265,19 @@ public function getConfigTreeBuilder()
->end()
->end()
->end()
->end()
;
}

->arrayNode('assets')
->performNoDeepMerging()
->addDefaultsIfNotSet()
->children()
->arrayNode('css')
->prototype('scalar')->end()
->info('The array of CSS assets to load in all backend pages.')
->end()
->arrayNode('js')
->prototype('scalar')->end()
->info('The array of JavaScript assets to load in all backend pages.')
->end()
->end()
->end()

->arrayNode('formats')
->performNoDeepMerging()
->addDefaultsIfNotSet()
->children()
->scalarNode('date')
->defaultValue('Y-m-d')
->info('The PHP date format applied to "date" field types.')
->example('d/m/Y (see http://php.net/manual/en/function.date.php)')
->end()
->scalarNode('time')
->defaultValue('H:i:s')
->info('The PHP time format applied to "time" field types.')
->example('h:i a (see http://php.net/date)')
->end()
->scalarNode('datetime')
->defaultValue('F j, Y H:i')
->info('The PHP date/time format applied to "datetime" field types.')
->example('l, F jS Y / h:i (see http://php.net/date)')
->end()
->scalarNode('number')
->info('The sprintf-compatible format applied to numeric values.')
->example('%.2d (see http://php.net/sprintf)')
->end()
->end()
->end()

private function addEntitiesSection(ArrayNodeDefinition $rootNode)
{
$rootNode
->children()
->variableNode('entities')
->defaultValue(array())
->info('The list of entities to manage in the administration zone.')
->end()
->end()
;

return $treeBuilder;
}
}
72 changes: 43 additions & 29 deletions Resources/doc/10-customizing-design.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
Chapter 10. Customizing the Visual Design of the Backend
========================================================

The current version of EasyAdmin doesn't support the concept of themes, but you
can fully customize its design using CSS and JavaScript files. Define the
`assets` option to load your own web assets:
The current version of EasyAdmin doesn't support the concept of themes.
However, you can customize lots of options related to the visual design of your
backend. All these options are defined under the global `design` option:

```yaml
easy_admin:
assets:
css:
- 'bundles/app/css/admin1.css'
- 'bundles/acmedemo/css/admin2.css'
js:
- 'bundles/app/js/admin1.js'
- 'bundles/acmedemo/js/admin2.js'
design:
# ...
```

Adding Custom Web Assets
------------------------

Use the `assets` option to define the web assets (CSS and JavaScript files)
that should be loaded in the backend layout:

```yaml
easy_admin:
design:
assets:
css:
- 'bundles/app/css/admin1.css'
- 'bundles/acmedemo/css/admin2.css'
js:
- 'bundles/app/js/admin1.js'
- 'bundles/acmedemo/js/admin2.js'
# ...
```

Expand All @@ -22,25 +35,26 @@ absolute) and links to them accordingly:

```yaml
easy_admin:
assets:
css:
# HTTP protocol-relative URL
- '//example.org/css/admin1.css'
# absolute non-secure URL
- 'http://example.org/css/admin2.css'
# absolute secure URL
- 'https://example.org/css/admin3.css'
# absolute internal bundle URL
- '/bundles/acmedemo/css/admin4.css'
# relative internal bundle URL
- 'bundles/app/css/admin5.css'
js:
# this option works exactly the same as the 'css' option
- '//example.org/js/admin1.js'
- 'http://example.org/js/admin2.js'
- 'https://example.org/js/admin3.js'
- '/bundles/acmedemo/js/admin4.js'
- 'bundles/app/js/admin5.js'
design:
assets:
css:
# HTTP protocol-relative URL
- '//example.org/css/admin1.css'
# absolute non-secure URL
- 'http://example.org/css/admin2.css'
# absolute secure URL
- 'https://example.org/css/admin3.css'
# absolute internal bundle URL
- '/bundles/acmedemo/css/admin4.css'
# relative internal bundle URL
- 'bundles/app/css/admin5.css'
js:
# this option works exactly the same as the 'css' option
- '//example.org/js/admin1.js'
- 'http://example.org/js/admin2.js'
- 'https://example.org/js/admin3.js'
- '/bundles/acmedemo/js/admin4.js'
- 'bundles/app/js/admin5.js'
# ...
```

Expand Down
4 changes: 2 additions & 2 deletions Resources/views/layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<link rel="stylesheet" href="{{ asset('bundles/easyadmin/stylesheet/admin.css') }}">
{% endblock %}

{% for css_asset in easyadmin_config('assets.css') %}
{% for css_asset in easyadmin_config('design.assets.css') %}
<link rel="stylesheet" href="{{ asset(css_asset) }}">
{% endfor %}

Expand Down Expand Up @@ -103,7 +103,7 @@
<script src="{{ asset('bundles/easyadmin/javascript/bootstrap.min.js') }}"></script>
<script src="{{ asset('bundles/easyadmin/javascript/admin.js') }}"></script>
{% endblock %}
{% for js_asset in easyadmin_config('assets.js') %}
{% for js_asset in easyadmin_config('design.assets.js') %}
<script src="{{ asset(js_asset) }}"></script>
{% endfor %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,15 @@ easy_admin:
label: action.edit
class: ''
icon: edit
design:
assets:
css: { }
js: { }
site_name: 'Easy Admin'
formats:
date: Y-m-d
time: 'H:i:s'
datetime: 'F j, Y H:i'
list:
actions: { }
max_results: 15
Expand All @@ -92,10 +100,3 @@ easy_admin:
actions: { }
show:
actions: { }
assets:
css: { }
js: { }
formats:
date: Y-m-d
time: 'H:i:s'
datetime: 'F j, Y H:i'
Loading

0 comments on commit bb2a957

Please sign in to comment.