Ver código fonte

Add an option to resize panels in edit view

Hugo Briand 11 anos atrás
pai
commit
b5e96e66ee

+ 12 - 11
Mapper/BaseGroupedMapper.php

@@ -18,11 +18,11 @@ abstract class BaseGroupedMapper extends BaseMapper
 {
 
     protected $currentGroup;
-    
+
     protected abstract function getGroups();
-    
+
     protected abstract function setGroups(array $groups);
-    
+
     /**
      * @param string $name
      * @param array  $options
@@ -32,25 +32,26 @@ abstract class BaseGroupedMapper extends BaseMapper
     public function with($name, array $options = array())
     {
         $groups = $this->getGroups();
-        
+
         if (!isset($groups[$name])) {
             $groups[$name] = array();
         }
 
         $groups[$name] = array_merge(array(
             'collapsed'          => false,
+            'class'              => false,
             'fields'             => array(),
             'description'        => false,
             'translation_domain' => null,
         ), $groups[$name], $options);
-        
+
         $this->setGroups($groups);
 
         $this->currentGroup = $name;
 
         return $this;
     }
-    
+
     /**
      * @return \Sonata\AdminBundle\Mapper\BaseGroupedMapper
      */
@@ -63,7 +64,7 @@ abstract class BaseGroupedMapper extends BaseMapper
 
     /**
      * Add the fieldname to the current group
-     * 
+     *
      * @param string $fieldName
      */
     protected function addFieldToCurrentGroup($fieldName)
@@ -79,12 +80,12 @@ abstract class BaseGroupedMapper extends BaseMapper
     }
 
     /**
-     * Return the name of the currently selected group. The method also makes 
+     * Return the name of the currently selected group. The method also makes
      * sure a valid group name is currently selected
-     * 
+     *
      * Note that this can have the side effect to change the "group" value
      * returned by the getGroup function
-     * 
+     *
      * @return string
      */
     protected function getCurrentGroupName()
@@ -94,5 +95,5 @@ abstract class BaseGroupedMapper extends BaseMapper
         }
         return $this->currentGroup;
     }
-    
+
 }

+ 33 - 3
Resources/doc/reference/action_create_edit.rst

@@ -3,11 +3,11 @@ Creating and Editing objects
 
 .. note::
 
-    This document is a stub representing a new work in progress. If you're reading 
-    this you can help contribute, **no matter what your experience level with Sonata 
+    This document is a stub representing a new work in progress. If you're reading
+    this you can help contribute, **no matter what your experience level with Sonata
     is**. Check out the `issues on Github`_ for more information about how to get involved.
 
-This document will cover the Create and Edit actions. It will cover configuration 
+This document will cover the Create and Edit actions. It will cover configuration
 of the fields and forms available in these views and any other relevant settings.
 
 
@@ -22,6 +22,36 @@ To do:
 - options available when adding fields, inc custom templates
 - link to the field_types document for more details about specific field types
 
+FormGroup options
+~~~~~~~~~~~~~~~~~
+
+When adding a form group to your edit/create form, you may specify some options for the group itself.
+
+- ``collapsed``: unused at the moment
+- ``class``: the class for your form group in the admin; by default, the value is set to ``col-md-12`` if you have only one formgroup in your form, otherwise to ``col-md-6``.
+- ``fields``: the fields in your form group (you should NOT override this unless you know what you're doing).
+- ``description``: to complete
+- ``translation_domain``: to complete
+
+To specify options, do as follow:
+
+.. code-block:: php
+
+<?php
+
+    public function configureFormFields(FormMapper $formMapper)
+    {
+        $formMapper
+            ->with('Addresses',
+                array(
+                    'class'       => 'col-md-8',
+                    'description' => 'Lorem ipsum',
+                    // ...
+                    ))
+                // ...
+            ->end()
+        ;
+
 
 Embedding other Admins
 ----------------------

+ 3 - 2
Resources/public/css/styles.css

@@ -223,9 +223,9 @@ td.sonata-ba-list-label {
 
 /* side filter */
 
-h4.filter_legend {
+.box .box-header h4.box-title.filter_legend {
     position: relative;
-    padding-left: 16px;
+    padding-left: 20px;
     cursor: pointer;
 }
 
@@ -241,6 +241,7 @@ h4.filter_legend:before {
     top: 50%;
     left: 2px;
     margin-top: -2px;
+    margin-left: 5px;
 }
 
 h4.filter_legend.active,

+ 4 - 0
Resources/views/CRUD/base_edit.html.twig

@@ -19,6 +19,10 @@ file that was distributed with this source code.
     {% endif %}
 {% endblock%}
 
+{% block navbar_title %}
+    {{ block('title') }}
+{% endblock %}
+
 {% block actions %}
     <li>{% include 'SonataAdminBundle:Button:show_button.html.twig' %}</li>
     <li>{% include 'SonataAdminBundle:Button:history_button.html.twig' %}</li>

+ 2 - 1
Resources/views/CRUD/base_edit_form.html.twig

@@ -24,8 +24,9 @@
             {% endblock %}
 
             {% block sonata_tab_content %}
+                {% set default_class = admin.formgroups|length > 1 ? 'col-md-6' : 'col-md-12' %}
                 {% for name, form_group in admin.formgroups %}
-                    <div class="col-md-{% if admin.formgroups|length > 1 %}6{% else %}12{% endif %}">
+                    <div class="{{ form_group.class|default(default_class) }}">
                         <div class="box box-success">
                             <div class="box-header">
                                 <h4 class="box-title">

+ 6 - 0
Resources/views/standard_layout.html.twig

@@ -18,6 +18,7 @@ file that was distributed with this source code.
 {% set _title        = block('title') %}
 {% set _breadcrumb   = block('breadcrumb') %}
 {% set _actions      = block('actions') %}
+{% set _navbar_title = block('navbar_title') %}
 <!DOCTYPE html>
 <html {% block html_attributes %}class="no-js"{% endblock %}>
     <head>
@@ -221,6 +222,11 @@ file that was distributed with this source code.
                                 {% block sonata_page_content_nav %}
                                     {% if _tab_menu is not empty or _actions is not empty %}
                                         <nav class="navbar navbar-default" role="navigation">
+                                            {% if _navbar_title is not empty %}
+                                                <div class="navbar-header">
+                                                    <span class="navbar-brand">{{ _navbar_title|raw }}</span>
+                                                </div>
+                                            {% endif %}
                                             <div class="container-fluid">
                                                 <div class="navbar-left">
                                                     {% if _tab_menu is not empty %}