Browse Source

Merge pull request #2040 from Bladrak/resizeFormOption

Add an option to resize panels in edit view
Thomas 11 years ago
parent
commit
53d65696cd

+ 12 - 11
Mapper/BaseGroupedMapper.php

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

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

@@ -3,11 +3,11 @@ Creating and Editing objects
 
 
 .. note::
 .. 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.
     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.
 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
 - options available when adding fields, inc custom templates
 - link to the field_types document for more details about specific field types
 - 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
 Embedding other Admins
 ----------------------
 ----------------------

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

@@ -223,9 +223,9 @@ td.sonata-ba-list-label {
 
 
 /* side filter */
 /* side filter */
 
 
-h4.filter_legend {
+.box .box-header h4.box-title.filter_legend {
     position: relative;
     position: relative;
-    padding-left: 16px;
+    padding-left: 20px;
     cursor: pointer;
     cursor: pointer;
 }
 }
 
 
@@ -241,6 +241,7 @@ h4.filter_legend:before {
     top: 50%;
     top: 50%;
     left: 2px;
     left: 2px;
     margin-top: -2px;
     margin-top: -2px;
+    margin-left: 5px;
 }
 }
 
 
 h4.filter_legend.active,
 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 %}
     {% endif %}
 {% endblock%}
 {% endblock%}
 
 
+{% block navbar_title %}
+    {{ block('title') }}
+{% endblock %}
+
 {% block actions %}
 {% block actions %}
     <li>{% include 'SonataAdminBundle:Button:show_button.html.twig' %}</li>
     <li>{% include 'SonataAdminBundle:Button:show_button.html.twig' %}</li>
     <li>{% include 'SonataAdminBundle:Button:history_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 %}
             {% endblock %}
 
 
             {% block sonata_tab_content %}
             {% block sonata_tab_content %}
+                {% set default_class = admin.formgroups|length > 1 ? 'col-md-6' : 'col-md-12' %}
                 {% for name, form_group in admin.formgroups %}
                 {% 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 box-success">
                             <div class="box-header">
                             <div class="box-header">
                                 <h4 class="box-title">
                                 <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 _title        = block('title') %}
 {% set _breadcrumb   = block('breadcrumb') %}
 {% set _breadcrumb   = block('breadcrumb') %}
 {% set _actions      = block('actions') %}
 {% set _actions      = block('actions') %}
+{% set _navbar_title = block('navbar_title') %}
 <!DOCTYPE html>
 <!DOCTYPE html>
 <html {% block html_attributes %}class="no-js"{% endblock %}>
 <html {% block html_attributes %}class="no-js"{% endblock %}>
     <head>
     <head>
@@ -221,6 +222,11 @@ file that was distributed with this source code.
                                 {% block sonata_page_content_nav %}
                                 {% block sonata_page_content_nav %}
                                     {% if _tab_menu is not empty or _actions is not empty %}
                                     {% if _tab_menu is not empty or _actions is not empty %}
                                         <nav class="navbar navbar-default" role="navigation">
                                         <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="container-fluid">
                                                 <div class="navbar-left">
                                                 <div class="navbar-left">
                                                     {% if _tab_menu is not empty %}
                                                     {% if _tab_menu is not empty %}