فهرست منبع

Added possibility to customize class and box class for groups on show admin page

Martin Hasoň 10 سال پیش
والد
کامیت
a610ed1d4d
2فایلهای تغییر یافته به همراه58 افزوده شده و 23 حذف شده
  1. 33 0
      Resources/doc/reference/action_show.rst
  2. 25 23
      Resources/views/CRUD/base_show.html.twig

+ 33 - 0
Resources/doc/reference/action_show.rst

@@ -21,7 +21,40 @@ To do:
 - targeting submodel fields using dot-separated notation
 - (Note, if this is very similar to the form documentation it can be combined)
 
+Group options
+~~~~~~~~~~~~~
 
+When adding a group to your show page, you may specify some options for the group itself.
+
+- ``collapsed``: unused at the moment
+- ``class``: the class for your group in the admin; by default, the value is set to ``col-md-12``.
+- ``fields``: the fields in your group (you should NOT override this unless you know what you're doing).
+- ``box_class``: the class for your group box in the admin; by default, the value is set to ``box box-primary``.
+- ``description``: to complete
+- ``translation_domain``: to complete
+
+To specify options, do as follow:
+
+.. code-block:: php
+
+    <?php
+
+    MyAdmin extends Admin
+    {
+        public function configureShowFields(ShowMapper $showMapper)
+        {
+            $showMapper
+                ->tab('General') // the tab call is optional
+                    ->with('Addresses', array(
+                        'class'       => 'col-md-8',
+                        'box_class'   => 'box box-solid box-danger',
+                        'description' => 'Lorem ipsum',
+                    ))
+                        // ...
+                    ->end()
+                ->end()
+            ;
+    }
 
 Customising the query used to show the object from within your Admin class
 --------------------------------------------------------------------------

+ 25 - 23
Resources/views/CRUD/base_show.html.twig

@@ -26,30 +26,32 @@ file that was distributed with this source code.
         {{ sonata_block_render_event('sonata.admin.show.top', { 'admin': admin, 'object': object }) }}
 
         {% for name, view_group in admin.showgroups %}
-            <div class="box box-primary">
-                {% if name %}
-                    <div class="box-header with-border">
-                        <h4 class="box-title">
-                            {% block show_title %}
-                                {{ admin.trans(name) }}
-                            {% endblock %}
-                        </h4>
+            <div class="{{ view_group.class | default('col-md-12') }}">
+                <div class="{{ view_group.box_class }}">
+                    {% if name %}
+                        <div class="box-header with-border">
+                            <h4 class="box-title">
+                                {% block show_title %}
+                                    {{ admin.trans(name) }}
+                                {% endblock %}
+                            </h4>
+                        </div>
+                    {% endif %}
+                    <div class="box-body table-responsive no-padding">
+                        <table class="table">
+                            <tbody>
+                            {% for field_name in view_group.fields %}
+                                {% block show_field %}
+                                    <tr class="sonata-ba-view-container">
+                                        {% if elements[field_name] is defined %}
+                                            {{ elements[field_name]|render_view_element(object) }}
+                                        {% endif %}
+                                    </tr>
+                                {% endblock %}
+                            {% endfor %}
+                            </tbody>
+                        </table>
                     </div>
-                {% endif %}
-                <div class="box-body table-responsive no-padding">
-                    <table class="table">
-                        <tbody>
-                        {% for field_name in view_group.fields %}
-                            {% block show_field %}
-                                <tr class="sonata-ba-view-container">
-                                    {% if elements[field_name] is defined %}
-                                        {{ elements[field_name]|render_view_element(object) }}
-                                    {% endif %}
-                                </tr>
-                            {% endblock %}
-                        {% endfor %}
-                        </tbody>
-                    </table>
                 </div>
             </div>
         {% endfor %}