浏览代码

Put add block into dedicated template & renamed option

Hugo Briand 11 年之前
父节点
当前提交
453c871992

+ 1 - 0
DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php

@@ -270,6 +270,7 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
         // make sure the default templates are defined
         $definedTemplates = array_merge(array(
             'user_block'               => 'SonataAdminBundle:Core:user_block.html.twig',
+            'add_block'                => 'SonataAdminBundle:Core:add_block.html.twig',
             'layout'                   => 'SonataAdminBundle::standard_layout.html.twig',
             'ajax'                     => 'SonataAdminBundle::ajax_layout.html.twig',
             'dashboard'                => 'SonataAdminBundle:Core:dashboard.html.twig',

+ 2 - 1
DependencyInjection/Configuration.php

@@ -78,7 +78,7 @@ class Configuration implements ConfigurationInterface
                         ->booleanNode('confirm_exit')->defaultValue(true)->end()
                         ->booleanNode('use_select2')->defaultValue(true)->end()
                         ->integerNode('pager_links')->defaultValue(null)->end()
-                        ->integerNode('dropdown_max_items_per_column')->defaultValue(2)->end()
+                        ->integerNode('dropdown_number_groups_per_colums')->defaultValue(2)->end()
                     ->end()
                 ->end()
                 ->arrayNode('dashboard')
@@ -146,6 +146,7 @@ class Configuration implements ConfigurationInterface
                     ->addDefaultsIfNotSet()
                     ->children()
                         ->scalarNode('user_block')->defaultValue('SonataAdminBundle:Core:user_block.html.twig')->cannotBeEmpty()->end()
+                        ->scalarNode('add_block')->defaultValue('SonataAdminBundle:Core:add_block.html.twig')->cannotBeEmpty()->end()
                         ->scalarNode('layout')->defaultValue('SonataAdminBundle::standard_layout.html.twig')->cannotBeEmpty()->end()
                         ->scalarNode('ajax')->defaultValue('SonataAdminBundle::ajax_layout.html.twig')->cannotBeEmpty()->end()
                         ->scalarNode('dashboard')->defaultValue('SonataAdminBundle:Core:dashboard.html.twig')->cannotBeEmpty()->end()

+ 2 - 1
Resources/doc/reference/configuration.rst

@@ -60,7 +60,7 @@ Full Configuration Options
                 confirm_exit:                           true      # enabled confirmation when quitting with unsaved changes
                 use_select2:                            true      # enable select2
                 pager_links:                            ~         # pager max links to display
-                dropdown_max_items_per_column:          2         # max items per column in dropdown menu (add button in top nav)
+                dropdown_number_groups_per_colums:          2         # max items per column in dropdown menu (add button in top nav)
             dashboard:
                 groups:
 
@@ -95,6 +95,7 @@ Full Configuration Options
                     label:                ~
             templates:
                 user_block:           SonataAdminBundle:Core:user_block.html.twig
+                add_block:            SonataAdminBundle:Core:add_block.html.twig
                 layout:               SonataAdminBundle::standard_layout.html.twig
                 ajax:                 SonataAdminBundle::ajax_layout.html.twig
                 dashboard:            SonataAdminBundle:Core:dashboard.html.twig

+ 2 - 0
Resources/doc/reference/templates.rst

@@ -72,6 +72,7 @@ There are several other templates that can be customized, enabling you to fine-t
 ``SonataAdminBundle``:
 
 * user_block: customizes the Twig block rendered by default in the top right corner of the admin interface, containing user information. Empty by defautl, see ``SonataUserBundle`` for a real example.
+* add_block: customizes the Twig block rendered by default in the top right corner of the admin interface, providing quick access to create operations on available admin classes.
 * history_revision_timestamp: customizes the way timestamps are rendered when using history related actions.
 * action: a generic template you can use for your custom actions
 * short_object_description: used by the ``getShortObjectDescriptionAction`` action from the ``HelperController``, this template displays a small description of a model instance.
@@ -116,6 +117,7 @@ You can specify your templates in the config.yml file, like so:
                 base_list_field:     SonataAdminBundle:CRUD:base_list_field.html.twig
                 list_block:          SonataAdminBundle:Block:block_admin_list.html.twig
                 user_block:          SonataAdminBundle:Core:user_block.html.twig
+                add_block:           SonataAdminBundle:Core:add_block.html.twig
                 pager_links:         SonataAdminBundle:Pager:links.html.twig
                 pager_results:       SonataAdminBundle:Pager:results.html.twig
                 history_revision_timestamp:  SonataAdminBundle:CRUD:history_revision_timestamp.html.twig

+ 57 - 0
Resources/views/Core/add_block.html.twig

@@ -0,0 +1,57 @@
+{% block user_block %}
+    {% set itemsPerColumn = admin_pool.getOption('dropdown_number_groups_per_colums') %}
+    {% set columnsCount = (admin_pool.dashboardgroups|length / itemsPerColumn)|round %}
+
+
+    <ul class="dropdown-menu{% if columnsCount > 1 %} multi-column{% endif %} dropdown-add"
+        {% if columnsCount > 1 %}style="width: {{ columnsCount*140 }}px;"{% endif %}
+            >
+        {% for group in admin_pool.dashboardgroups %}
+            {% set display = (group.roles is empty or is_granted('ROLE_SUPER_ADMIN') ) %}
+            {% for role in group.roles if not display %}
+                {% set display = is_granted(role) %}
+            {% endfor %}
+
+            {# Do not display the group label if no item in group is available #}
+            {% set item_count = 0 %}
+            {% if display %}
+                {% for admin in group.items if item_count == 0 %}
+                    {% if admin.hasroute('list') and admin.isGranted('LIST') %}
+                        {% set item_count = item_count+1 %}
+                    {% endif %}
+                {% endfor %}
+            {% endif %}
+
+            {% if display and (item_count > 0) %}
+                {% if columnsCount > 1 and loop.index0 % itemsPerColumn == 0 %}
+                    {% if loop.first %}
+                        <div class="row">
+                    {% endif %}
+                    <div class="col-md-{{ (12/columnsCount)|round }}">
+                    <ul class="dropdown-menu">
+                {% endif %}
+
+                <li role="presentation" class="dropdown-header">{{ group.label|trans({}, group.label_catalogue) }}</li>
+                {% for admin in group.items %}
+                    {% if admin.hasroute('create') and admin.isGranted('CREATE') %}
+                        <li role="presentation">
+                            <a role="menuitem" tabindex="-1" href="{{ admin.generateUrl('create')}}">{{ admin.label|trans({}, admin.translationdomain) }}</a>
+                        </li>
+                    {% endif %}
+                {% endfor %}
+
+                {% if not loop.last and loop.index % itemsPerColumn != 0 %}
+                    <li role="presentation" class="divider"></li>
+                {% endif %}
+
+            {% if loop.length > itemsPerColumn and loop.index % itemsPerColumn == 0 %}
+                </ul>
+                </div>
+            {% endif %}
+                {% if loop.length > itemsPerColumn and loop.last %}
+                    </div>
+                {% endif %}
+            {% endif %}
+        {% endfor %}
+    </ul>
+{% endblock %}

+ 1 - 58
Resources/views/standard_layout.html.twig

@@ -156,64 +156,7 @@ file that was distributed with this source code.
                                             <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                                                 <i class="fa fa-plus-square fa-fw"></i> <i class="fa fa-caret-down"></i>
                                             </a>
-                                            {% block sonata_add_menu %}
-                                                {% set itemsPerColumn = admin_pool.getOption('dropdown_max_items_per_column') %}
-                                                {% set columnsCount = (admin_pool.dashboardgroups|length / itemsPerColumn)|round %}
-
-
-                                                <ul class="dropdown-menu{% if columnsCount > 1 %} multi-column{% endif %} dropdown-add"
-                                                    {% if columnsCount > 1 %}style="width: {{ columnsCount*140 }}px;"{% endif %}
-                                                        >
-                                                    {% for group in admin_pool.dashboardgroups %}
-                                                        {% set display = (group.roles is empty or is_granted('ROLE_SUPER_ADMIN') ) %}
-                                                        {% for role in group.roles if not display %}
-                                                            {% set display = is_granted(role) %}
-                                                        {% endfor %}
-
-                                                        {# Do not display the group label if no item in group is available #}
-                                                        {% set item_count = 0 %}
-                                                        {% if display %}
-                                                            {% for admin in group.items if item_count == 0 %}
-                                                                {% if admin.hasroute('list') and admin.isGranted('LIST') %}
-                                                                    {% set item_count = item_count+1 %}
-                                                                {% endif %}
-                                                            {% endfor %}
-                                                        {% endif %}
-
-                                                        {% if display and (item_count > 0) %}
-                                                            {% if columnsCount > 1 and loop.index0 % itemsPerColumn == 0 %}
-                                                                {% if loop.first %}
-                                                                    <div class="row">
-                                                                {% endif %}
-                                                                <div class="col-md-{{ (12/columnsCount)|round }}">
-                                                                    <ul class="dropdown-menu">
-                                                            {% endif %}
-
-                                                            <li role="presentation" class="dropdown-header">{{ group.label|trans({}, group.label_catalogue) }}</li>
-                                                            {% for admin in group.items %}
-                                                                {% if admin.hasroute('create') and admin.isGranted('CREATE') %}
-                                                                    <li role="presentation">
-                                                                        <a role="menuitem" tabindex="-1" href="{{ admin.generateUrl('create')}}">{{ admin.label|trans({}, admin.translationdomain) }}</a>
-                                                                    </li>
-                                                                {% endif %}
-                                                            {% endfor %}
-
-                                                            {% if not loop.last and loop.index % itemsPerColumn != 0 %}
-                                                                <li role="presentation" class="divider"></li>
-                                                            {% endif %}
-
-                                                            {% if loop.length > itemsPerColumn and loop.index % itemsPerColumn == 0 %}
-                                                                    </ul>
-                                                                </div>
-                                                            {% endif %}
-                                                            {% if loop.length > itemsPerColumn and loop.last %}
-                                                                </div>
-                                                            {% endif %}
-                                                        {% endif %}
-                                                    {% endfor %}
-
-                                                {% endblock %}
-                                            </ul>
+                                            {% include admin_pool.getTemplate('add_block') %}
                                         </li>
                                         <li class="dropdown">
                                             <a class="dropdown-toggle" data-toggle="dropdown" href="#">