Pārlūkot izejas kodu

improve sf3.0 support

Thomas Rabaix 9 gadi atpakaļ
vecāks
revīzija
ab159e9b6f

+ 4 - 4
Controller/CRUDController.php

@@ -113,13 +113,15 @@ class CRUDController extends Controller
      */
     protected function configure()
     {
-        $adminCode = $this->container->get('request')->get('_sonata_admin');
+        $request = $this->getRequest();
+
+        $adminCode = $request->get('_sonata_admin');
 
         if (!$adminCode) {
             throw new \RuntimeException(sprintf(
                 'There is no `_sonata_admin` defined for the controller `%s` and the current route `%s`',
                 get_class($this),
-                $this->container->get('request')->get('_route')
+                $request->get('_route')
             ));
         }
 
@@ -139,8 +141,6 @@ class CRUDController extends Controller
             $rootAdmin = $rootAdmin->getParent();
         }
 
-        $request = $this->container->get('request');
-
         $rootAdmin->setRequest($request);
 
         if ($request->get('uniqid')) {

+ 9 - 0
DependencyInjection/SonataAdminExtension.php

@@ -176,6 +176,15 @@ BOOM
             'integer'  => '',
             'datetime' => 'sonata-medium-date',
             'date'     => 'sonata-medium-date',
+
+            // SF3+
+            'Symfony\Component\Form\Extension\Core\Type\ChoiceType' => '',
+            'Symfony\Component\Form\Extension\Core\Type\DateType' => 'sonata-medium-date',
+            'Symfony\Component\Form\Extension\Core\Type\DateTimeType' => 'sonata-medium-date',
+            'Symfony\Component\Form\Extension\Core\Type\EmailType' => '',
+            'Symfony\Component\Form\Extension\Core\Type\IntegerType' => '',
+            'Symfony\Component\Form\Extension\Core\Type\TextareaType' => '',
+            'Symfony\Component\Form\Extension\Core\Type\TextType' => '',
         );
 
         $container->getDefinition('sonata.admin.form.extension.field')

+ 9 - 2
Form/Extension/Field/Type/FormTypeFieldExtension.php

@@ -91,8 +91,15 @@ class FormTypeFieldExtension extends AbstractTypeExtension
     protected function getClass(FormBuilderInterface $formBuilder)
     {
         foreach ($this->getTypes($formBuilder) as $type) {
-            if (isset($this->defaultClasses[$type->getName()])) {
-                return $this->defaultClasses[$type->getName()];
+
+            if (!method_exists($type, 'getName')) { // SF3.0+
+                $name = get_class($type);
+            } else {
+                $name = $type->getName();
+            }
+
+            if (isset($this->defaultClasses[$name])) {
+                return $this->defaultClasses[$name];
             }
         }
 

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

@@ -11,7 +11,8 @@
         <form
               {% if sonata_admin.adminPool.getOption('form_type') == 'horizontal' %}class="form-horizontal"{% endif %}
               role="form"
-              action="{% block sonata_form_action_url %}{{ admin.generateUrl(url, {'id': admin.id(object), 'uniqid': admin.uniqid, 'subclass': app.request.get('subclass')}) }}{% endblock %}" {{ form_enctype(form) }}
+              action="{% block sonata_form_action_url %}{{ admin.generateUrl(url, {'id': admin.id(object), 'uniqid': admin.uniqid, 'subclass': app.request.get('subclass')}) }}{% endblock %}"
+              {% if form.vars.multipart %} enctype="multipart/form-data"{% endif %}
               method="POST"
               {% if not sonata_admin.adminPool.getOption('html5_validate') %}novalidate="novalidate"{% endif %}
               >

+ 7 - 2
Resources/views/Form/form_admin_fields.html.twig

@@ -151,15 +151,20 @@ file that was distributed with this source code.
 
 {% block choice_widget_collapsed %}
 {% spaceless %}
-    {% if required and empty_value is none and not empty_value_in_choices and not multiple %}
+
+    {# this line only work with sf<3, as empty_value_in_choices and empty_value are now deprecated#}
+    {% if required and empty_value is defined and empty_value_in_choices is defined and empty_value is none and not empty_value_in_choices and not multiple %}
         {% set required = false %}
     {% endif %}
+
     {% set attr = attr|merge({'class': attr.class|default('') ~ ' form-control'}) %}
     {% if (sortable is defined) and sortable and multiple %}
         {{ block('sonata_type_choice_multiple_sortable') }}
     {% else %}
         <select {{ block('widget_attributes') }}{% if multiple %} multiple="multiple"{% endif %} >
-            {% if empty_value is not none %}
+
+            {# this line only work with sf<3, as empty_value_in_choices and empty_value are now deprecated#}
+            {% if empty_value is defined and empty_value is not none %}
                 <option value=""{% if required and value is empty %} selected="selected"{% endif %}>
                     {% if not sonata_admin.admin %}
                         {{- empty_value|trans({}, translation_domain) -}}

+ 1 - 1
Resources/views/Menu/sonata_menu.html.twig

@@ -2,7 +2,7 @@
 
 {% block root %}
     {%- set listAttributes = item.childrenAttributes|merge({'class': 'sidebar-menu'}) %}
-    {%- set request        = item.extra('request') %}
+    {%- set request        = item.extra('request') ?: app.request %}
     {{ block('list') -}}
 {% endblock %}