浏览代码

Merge branch '2.0' of github.com:sonata-project/SonataAdminBundle into persist-preview-mode-2.0

Thanos Polymeneas 13 年之前
父节点
当前提交
6050b45769

+ 2 - 4
Admin/Admin.php

@@ -619,8 +619,8 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
             return;
         }
 
-        $collection = new FieldDescriptionCollection();
-        $mapper = new ShowMapper($this->showBuilder, $collection, $this);
+        $this->show = new FieldDescriptionCollection();
+        $mapper = new ShowMapper($this->showBuilder, $this->show, $this);
 
         $this->configureShowField($mapper); // deprecated, use configureShowFields instead
         $this->configureShowFields($mapper);
@@ -628,8 +628,6 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
         foreach ($this->getExtensions() as $extension) {
             $extension->configureShowFields($mapper);
         }
-
-        $this->show = $collection;
     }
 
     /**

+ 7 - 0
Admin/AdminInterface.php

@@ -540,4 +540,11 @@ interface AdminInterface
      * @return void
      */
     function setParent(AdminInterface $admin);
+    
+    /**
+     * @param string $name
+     *
+     * @return null|string
+     */
+    public function getTemplate($name);
 }

+ 8 - 0
CHANGELOG.md

@@ -1,6 +1,14 @@
 CHANGELOG
 =========
 
+### 2012-06-05
+
+* [BC BREAK] Fix bug introduces by 09334d81, now an admin must have the role ``ROLE_SONATA_ADMIN`` to see the top bar navigation
+
+### 2012-05-31
+
+* Update batch action confirmation message (breaks some translations)
+
 ### 2012-05-02
 
 * [BC BREAK] add ProxyQueryInterface hint into the FilterInterface class

+ 1 - 1
Controller/CRUDController.php

@@ -385,7 +385,7 @@ class CRUDController extends Controller
                 'action'   => 'list',
                 'datagrid' => $datagrid,
                 'form'     => $formView,
-                'data'     => json_encode($data),
+                'data'     => $data,
             ));
         }
 

+ 11 - 3
Controller/HelperController.php

@@ -178,9 +178,17 @@ class HelperController
             }
         }
 
-        $description = sprintf('<a href="%s" target="new">%s</a>', $admin->generateUrl('edit', array('id' => $objectId)), $description);
-
-        return new Response($description);
+        $url = $admin->generateUrl('edit', array('id' => $objectId));
+        
+        $htmlOutput = $this->twig->render($admin->getTemplate('short_object_description'),
+            array(
+                'description' => $description,
+                'object' => $object,
+                'url' => $url
+            )
+        );
+
+        return new Response($htmlOutput);
     }
 
     /**

+ 11 - 10
DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php

@@ -246,16 +246,17 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
 
         // make sure the default templates are defined
         $definedTemplates = array_merge(array(
-            'user_block'        => 'SonataAdminBundle:Core:user_block.html.twig',
-            'layout'            => 'SonataAdminBundle::standard_layout.html.twig',
-            'ajax'              => 'SonataAdminBundle::ajax_layout.html.twig',
-            'dashboard'         => 'SonataAdminBundle:Core:dashboard.html.twig',
-            'list'              => 'SonataAdminBundle:CRUD:list.html.twig',
-            'show'              => 'SonataAdminBundle:CRUD:show.html.twig',
-            'edit'              => 'SonataAdminBundle:CRUD:edit.html.twig',
-            'history'           => 'SonataAdminBundle:CRUD:history.html.twig',
-            'history_revision'  => 'SonataAdminBundle:CRUD:history_revision.html.twig',
-            'action'            => 'SonataAdminBundle:CRUD:action.html.twig',
+            'user_block'               => 'SonataAdminBundle:Core:user_block.html.twig',
+            'layout'                   => 'SonataAdminBundle::standard_layout.html.twig',
+            'ajax'                     => 'SonataAdminBundle::ajax_layout.html.twig',
+            'dashboard'                => 'SonataAdminBundle:Core:dashboard.html.twig',
+            'list'                     => 'SonataAdminBundle:CRUD:list.html.twig',
+            'show'                     => 'SonataAdminBundle:CRUD:show.html.twig',
+            'edit'                     => 'SonataAdminBundle:CRUD:edit.html.twig',
+            'history'                  => 'SonataAdminBundle:CRUD:history.html.twig',
+            'history_revision'         => 'SonataAdminBundle:CRUD:history_revision.html.twig',
+            'action'                   => 'SonataAdminBundle:CRUD:action.html.twig',
+            'short_object_description' => 'SonataAdminBundle:Helper:short-object-description.html.twig',
         ), $definedTemplates);
 
         $definition->addMethodCall('setTemplates', array($definedTemplates));

+ 1 - 0
DependencyInjection/Configuration.php

@@ -136,6 +136,7 @@ class Configuration implements ConfigurationInterface
                         ->scalarNode('history')->defaultValue('SonataAdminBundle:CRUD:history.html.twig')->cannotBeEmpty()->end()
                         ->scalarNode('history_revision')->defaultValue('SonataAdminBundle:CRUD:history_revision.html.twig')->cannotBeEmpty()->end()
                         ->scalarNode('action')->defaultValue('SonataAdminBundle:CRUD:action.html.twig')->cannotBeEmpty()->end()
+                        ->scalarNode('short_object_description')->defaultValue('SonataAdminBundle:Helper:short-object-description.html.twig')->cannotBeEmpty()->end()
                     ->end()
                 ->end()
             ->end()

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

@@ -16,6 +16,9 @@ By default, an Admin class uses a set of templates, it is possible to tweak the
             show:    SonataAdminBundle:CRUD:show.html.twig
             edit:    SonataAdminBundle:CRUD:edit.html.twig
             history:  SonataAdminBundle:CRUD:history.html.twig
+            
+            # default values of helper templates
+            short_object_description: SonataAdminBundle:Helper:short-object-description.html.twig
 
 
 Usage of each template :
@@ -27,6 +30,7 @@ Usage of each template :
 * show : the template to use for the show action
 * edit : the template to use for the edit and create action
 * history : the template to use for the history / audit action
+* short_object_description: used to represent the entity in one-to-one/many-to-one relations
 
 The default values will be set only if the ``Admin::setTemplates`` is not called by the Container.
 

+ 5 - 1
Resources/translations/SonataAdminBundle.en.xliff

@@ -184,7 +184,11 @@
             </trans-unit>
             <trans-unit id="message_batch_confirmation">
                 <source>message_batch_confirmation</source>
-                <target>Are you sure you want to confirm this action and execute it for all of the selected elements?</target>
+                <target>Are you sure you want to confirm this action and execute it for the selected element?|Are you sure you want to confirm this action and execute it for the %count% selected elements?</target>
+            </trans-unit>
+            <trans-unit id="message_batch_all_confirmation">
+                <source>message_batch_all_confirmation</source>
+                <target>Are you sure you want to confirm this action and execute it for all the elements?</target>
             </trans-unit>
             <trans-unit id="btn_execute_batch_action">
                 <source>btn_execute_batch_action</source>

+ 5 - 1
Resources/translations/SonataAdminBundle.fr.xliff

@@ -184,7 +184,11 @@
             </trans-unit>
             <trans-unit id="message_batch_confirmation">
                 <source>message_batch_confirmation</source>
-                <target>Êtes-vous sûre de vouloir confirmer cette action et de l'exécuter pour tous les éléments sélectionnés?</target>
+                <target>Êtes-vous sûr de vouloir confirmer cette action et de l'exécuter pour l'élément sélectionné?|Êtes-vous sûr de vouloir confirmer cette action et de l'exécuter pour les %count% éléments sélectionnés?</target>
+            </trans-unit>
+            <trans-unit id="message_batch_all_confirmation">
+                <source>message_batch_all_confirmation</source>
+                <target>Êtes-vous sûr de vouloir confirmer cette action et de l'exécuter pour tous les éléments?</target>
             </trans-unit>
             <trans-unit id="btn_execute_batch_action">
                 <source>btn_execute_batch_action</source>

+ 6 - 2
Resources/views/CRUD/batch_confirmation.html.twig

@@ -32,12 +32,16 @@ file that was distributed with this source code.
 
         <h1>{% trans from 'SonataAdminBundle' %}title_batch_confirmation{% endtrans %}</h1>
 
-        {% trans from 'SonataAdminBundle' %}message_batch_confirmation{% endtrans %}
+        {% if data.all_elements %}
+            {% trans from 'SonataAdminBundle' %}message_batch_all_confirmation{% endtrans %}
+        {% else %}
+            {% transchoice data.idx|length with {'%count%': data.idx|length} from 'SonataAdminBundle' %}message_batch_confirmation{% endtranschoice %}
+        {% endif %}
 
         <div class="actions">
             <form action="{{ admin.generateUrl('batch', admin.filterParameters) }}" method="POST" >
                 <input type="hidden" name="confirmation" value="ok" />
-                <input type="hidden" name="data" value="{{ data }}" />
+                <input type="hidden" name="data" value="{{ data|json_encode }}" />
 
                 <div style="display: none">
                     {{ form_rest(form) }}

+ 1 - 3
Resources/views/Form/form_admin_fields.html.twig

@@ -9,8 +9,6 @@ file that was distributed with this source code.
 
 #}
 
-{% extends 'SonataAdminBundle:Form:silex_form_div_layout.html.twig' %}
-
 {# Labels #}
 {% block generic_label %}
 {% spaceless %}
@@ -80,7 +78,7 @@ file that was distributed with this source code.
 
 {% block field_row %}
     {% if sonata_admin is not defined or not sonata_admin_enabled or not sonata_admin.field_description %}
-        {{ parent() }}
+        {{ form_row(form) }}
     {% else %}
         <div class="clearfix{% if errors|length > 0%} error{%endif%}" id="sonata-ba-field-container-{{ id }}">
             {% block label %}

+ 1 - 205
Resources/views/Form/silex_form_div_layout.html.twig

@@ -1,29 +1,5 @@
 {# Widgets #}
 
-{% block form_widget %}
-{% spaceless %}
-    <div {{ block('widget_container_attributes') }}>
-        {{ block('field_rows') }}
-        {{ form_rest(form) }}
-    </div>
-{% endspaceless %}
-{% endblock form_widget %}
-
-{% block collection_widget %}
-{% spaceless %}
-    {% if prototype is defined %}
-        {% set attr = attr|merge({'data-prototype': form_row(prototype) }) %}
-    {% endif %}
-    {{ block('form_widget') }}
-{% endspaceless %}
-{% endblock collection_widget %}
-
-{% block textarea_widget %}
-{% spaceless %}
-    <textarea {{ block('widget_attributes') }}>{{ value }}</textarea>
-{% endspaceless %}
-{% endblock textarea_widget %}
-
 {% block choice_widget %}
 {% spaceless %}
     {% if expanded %}
@@ -42,7 +18,7 @@
         {% if preferred_choices|length > 0 %}
             {% set options = preferred_choices %}
             {{ block('widget_choice_options') }}
-            {% if choices|length > 0 %}
+            {% if choices|length > 0 and separator is not none %}
                 <option disabled="disabled">{{ separator }}</option>
             {% endif %}
         {% endif %}
@@ -53,103 +29,6 @@
 {% endspaceless %}
 {% endblock choice_widget %}
 
-{% block checkbox_widget %}
-{% spaceless %}
-    <input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
-{% endspaceless %}
-{% endblock checkbox_widget %}
-
-{% block radio_widget %}
-{% spaceless %}
-    <input type="radio" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
-{% endspaceless %}
-{% endblock radio_widget %}
-
-{% block datetime_widget %}
-{% spaceless %}
-    {% if widget == 'single_text' %}
-        {{ block('field_widget') }}
-    {% else %}
-        <div {{ block('widget_container_attributes') }}>
-            {{ form_errors(form.date) }}
-            {{ form_errors(form.time) }}
-            {{ form_widget(form.date) }}
-            {{ form_widget(form.time) }}
-        </div>
-    {% endif %}
-{% endspaceless %}
-{% endblock datetime_widget %}
-
-{% block date_widget %}
-{% spaceless %}
-    {% if widget == 'single_text' %}
-        {{ block('field_widget') }}
-    {% else %}
-        <div {{ block('widget_container_attributes') }}>
-            {{ date_pattern|replace({
-                '{{ year }}':  form_widget(form.year),
-                '{{ month }}': form_widget(form.month),
-                '{{ day }}':   form_widget(form.day),
-            })|raw }}
-        </div>
-    {% endif %}
-{% endspaceless %}
-{% endblock date_widget %}
-
-{% block time_widget %}
-{% spaceless %}
-    {% if widget == 'single_text' %}
-        {{ block('field_widget') }}
-    {% else %}
-        <div {{ block('widget_container_attributes') }}>
-            {{ form_widget(form.hour, { 'attr': { 'size': '1' } }) }}:{{ form_widget(form.minute, { 'attr': { 'size': '1' } }) }}{% if with_seconds %}:{{ form_widget(form.second, { 'attr': { 'size': '1' } }) }}{% endif %}
-        </div>
-    {% endif %}
-{% endspaceless %}
-{% endblock time_widget %}
-
-{% block number_widget %}
-{% spaceless %}
-    {# type="number" doesn't work with floats #}
-    {% set type = type|default('text') %}
-    {{ block('field_widget') }}
-{% endspaceless %}
-{% endblock number_widget %}
-
-{% block integer_widget %}
-{% spaceless %}
-    {% set type = type|default('number') %}
-    {{ block('field_widget') }}
-{% endspaceless %}
-{% endblock integer_widget %}
-
-{% block money_widget %}
-{% spaceless %}
-    {{ money_pattern|replace({ '{{ widget }}': block('field_widget') })|raw }}
-{% endspaceless %}
-{% endblock money_widget %}
-
-{% block url_widget %}
-{% spaceless %}
-    {% set type = type|default('url') %}
-    {{ block('field_widget') }}
-{% endspaceless %}
-{% endblock url_widget %}
-
-{% block search_widget %}
-{% spaceless %}
-    {% set type = type|default('search') %}
-    {{ block('field_widget') }}
-{% endspaceless %}
-{% endblock search_widget %}
-
-{% block percent_widget %}
-{% spaceless %}
-    {% set type = type|default('text') %}
-    {{ block('field_widget') }} %
-{% endspaceless %}
-{% endblock percent_widget %}
-
 {% block field_widget %}
 {% spaceless %}
     {% set type = type|default('text') %}
@@ -157,25 +36,6 @@
 {% endspaceless %}
 {% endblock field_widget %}
 
-{% block password_widget %}
-{% spaceless %}
-    {% set type = type|default('password') %}
-    {{ block('field_widget') }}
-{% endspaceless %}
-{% endblock password_widget %}
-
-{% block hidden_widget %}
-    {% set type = type|default('hidden') %}
-    {{ block('field_widget') }}
-{% endblock hidden_widget %}
-
-{% block email_widget %}
-{% spaceless %}
-    {% set type = type|default('email') %}
-    {{ block('field_widget') }}
-{% endspaceless %}
-{% endblock email_widget %}
-
 {# Labels #}
 
 {% block generic_label %}
@@ -196,27 +56,8 @@
 {% endspaceless %}
 {% endblock %}
 
-{% block field_label %}
-{% spaceless %}
-    {% set attr = attr|merge({'for': id}) %}
-    {{ block('generic_label') }}
-{% endspaceless %}
-{% endblock field_label %}
-
-{% block form_label %}
-{% spaceless %}
-    {{ block('generic_label') }}
-{% endspaceless %}
-{% endblock form_label %}
-
 {# Rows #}
 
-{% block repeated_row %}
-{% spaceless %}
-    {{ block('field_rows') }}
-{% endspaceless %}
-{% endblock repeated_row %}
-
 {% block field_row %}
 {% spaceless %}
     <div class="clearfix {{ (0 < form_errors(form)|length)? 'error':'' }} ">
@@ -229,18 +70,8 @@
 {% endspaceless %}
 {% endblock field_row %}
 
-{% block hidden_row %}
-    {{ form_widget(form) }}
-{% endblock hidden_row %}
-
 {# Misc #}
 
-{% block field_enctype %}
-{% spaceless %}
-    {% if multipart %}enctype="multipart/form-data"{% endif %}
-{% endspaceless %}
-{% endblock field_enctype %}
-
 {% block field_errors %}
 {% spaceless %}
     {% if errors|length > 0 %}
@@ -260,38 +91,3 @@
     {% endif %}
 {% endspaceless %}
 {% endblock field_errors %}
-
-{% block field_rest %}
-{% spaceless %}
-    {% for child in form %}
-        {% if not child.rendered %}
-            {{ form_row(child) }}
-        {% endif %}
-    {% endfor %}
-{% endspaceless %}
-{% endblock field_rest %}
-
-{# Support #}
-
-{% block field_rows %}
-{% spaceless %}
-    {{ form_errors(form) }}
-    {% for child in form %}
-        {{ form_row(child) }}
-    {% endfor %}
-{% endspaceless %}
-{% endblock field_rows %}
-
-{% block widget_attributes %}
-{% spaceless %}
-    id="{{ id }}" name="{{ full_name }}"{% if read_only %} disabled="disabled"{% endif %}{% if required %} required="required"{% endif %}{% if max_length %} maxlength="{{ max_length }}"{% endif %}{% if pattern %} pattern="{{ pattern }}"{% endif %}
-    {% for attrname,attrvalue in attr %}{{attrname}}="{{attrvalue}}" {% endfor %}
-{% endspaceless %}
-{% endblock widget_attributes %}
-
-{% block widget_container_attributes %}
-{% spaceless %}
-    id="{{ id }}"
-    {% for attrname,attrvalue in attr %}{{attrname}}="{{attrvalue}}" {% endfor %}
-{% endspaceless %}
-{% endblock widget_container_attributes %}

+ 1 - 0
Resources/views/Helper/short-object-description.html.twig

@@ -0,0 +1 @@
+<a href="{{ url }}" target="new">{{ description }}</a>

+ 27 - 12
Resources/views/standard_layout.html.twig

@@ -84,18 +84,33 @@ file that was distributed with this source code.
                                 </a>
                             {% endblock %}
                             <ul class="nav">
-                                {% for group in admin_pool.dashboardgroups %}
-                                    <li class="dropdown">
-                                        <a href="#" class="dropdown-toggle">{{ group.label|trans({}, group.label_catalogue) }}</a>
-                                        <ul class="dropdown-menu">
-                                            {% for admin in group.items %}
-                                                {% if admin.hasroute('create') and admin.isGranted('CREATE') or admin.hasroute('list') and admin.isGranted('LIST') %}
-                                                    <li><a href="{{ admin.generateUrl('list')}}">{{ admin.label|trans({}, admin.translationdomain) }}</a></li>
-                                                {% endif %}
-                                            {% endfor %}
-                                        </ul>
-                                    </li>
-                                {% endfor %}
+
+                                {% block sonata_top_bar_nav %}
+                                    {# There is no hasRole in a TokenInterface ... #}
+                                    {% set allowed = false %}
+                                    {% if app.security %}
+                                        {% for role in app.security.token.roles %}
+                                            {% if not allowed %}
+                                                {% set allowed = role.role == 'ROLE_SONATA_ADMIN' %}
+                                            {% endif %}
+                                        {% endfor %}
+                                    {% endif %}
+
+                                    {% if allowed %}
+                                        {% for group in admin_pool.dashboardgroups %}
+                                            <li class="dropdown">
+                                                <a href="#" class="dropdown-toggle">{{ group.label|trans({}, group.label_catalogue) }}</a>
+                                                <ul class="dropdown-menu">
+                                                    {% for admin in group.items %}
+                                                        {% if admin.hasroute('create') and admin.isGranted('CREATE') or admin.hasroute('list') and admin.isGranted('LIST') %}
+                                                            <li><a href="{{ admin.generateUrl('list')}}">{{ admin.label|trans({}, admin.translationdomain) }}</a></li>
+                                                        {% endif %}
+                                                    {% endfor %}
+                                                </ul>
+                                            </li>
+                                        {% endfor %}
+                                    {% endif %}
+                                {% endblock %}
                             </ul>
 
                             <p class="pull-right">{% include admin_pool.getTemplate('user_block') %}</p>

+ 11 - 1
Tests/Controller/AdminHelperTest.php

@@ -93,8 +93,11 @@ class AdminHelperTest extends \PHPUnit_Framework_TestCase
 
     public function testgetShortObjectDescriptionActionObject()
     {
+        $mockTemplate = 'AdminHelperTest:mock-short-object-description.html.twig';
+        
         $admin = $this->getMock('Sonata\AdminBundle\Admin\AdminInterface');
         $admin->expects($this->once())->method('setUniqid');
+        $admin->expects($this->once())->method('getTemplate')->will($this->returnValue($mockTemplate));
         $admin->expects($this->once())->method('getObject')->will($this->returnValue(new AdminControllerHelper_Foo));
         $admin->expects($this->once())->method('generateUrl')->will($this->returnCallback(function($name, $parameters) {
             if ($name != 'edit') {
@@ -110,7 +113,14 @@ class AdminHelperTest extends \PHPUnit_Framework_TestCase
         $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
         $container->expects($this->any())->method('get')->will($this->returnValue($admin));
 
-        $twig = new Twig;
+        $twig = $this->getMock('Twig_Environment');
+        
+        $twig->expects($this->once())->method('render')
+            ->with($mockTemplate)
+            ->will($this->returnCallback(function($templateName, $templateParams) {
+                return sprintf('<a href="%s" target="new">%s</a>', $templateParams['url'], $templateParams['description']);
+            }));
+            
         $request = new Request(array(
             'code'     => 'sonata.post.admin',
             'objectId' => 42,