Bladeren bron

date range type added

Pat Haggerty 13 jaren geleden
bovenliggende
commit
4dddc20c2c

+ 39 - 0
Form/Type/DateRangeType.php

@@ -0,0 +1,39 @@
+<?php
+/*
+ * This file is part of the Sonata package.
+ *
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ *
+ */
+
+namespace Sonata\AdminBundle\Form\Type;
+
+use Symfony\Component\Form\AbstractType;
+use Symfony\Component\Form\FormTypeInterface;
+use Symfony\Component\Form\FormBuilder;
+
+use Symfony\Component\Translation\TranslatorInterface;
+
+class DateRangeType extends AbstractType
+{
+    protected $translator;
+
+    public function __construct(TranslatorInterface $translator)
+    {
+        $this->translator = $translator;
+    }
+
+    public function buildForm(FormBuilder $builder, array $options)
+    {
+        $builder->add('start', 'date', array('required' => false));
+        $builder->add('end', 'date', array('required' => false));
+    }
+    
+    public function getName()
+    {
+        return 'sonata_type_date_range';
+    }
+}

+ 2 - 3
Form/Type/Filter/DateRangeType.php

@@ -39,7 +39,7 @@ class DateRangeType extends AbstractType
      */
     public function getName()
     {
-        return 'sonata_type_filter_daterange';
+        return 'sonata_type_filter_date_range';
     }
 
     public function buildForm(FormBuilder $builder, array $options)
@@ -50,8 +50,7 @@ class DateRangeType extends AbstractType
 
         $builder
             ->add('type', 'choice', array('choices' => $choices, 'required' => false))
-            ->add('value', 'date', array('required' => false))
-            ->add('valueb', 'date', array('required' => false))
+            ->add('value', 'sonata_type_date_range', array('required' => false))
         ;
     }
 

+ 6 - 0
Resources/config/form_types.xml

@@ -32,6 +32,12 @@
 
             <argument type="service" id="translator" />
         </service>
+        
+        <service id="sonata.admin.form.type.date_range" class="Sonata\AdminBundle\Form\Type\DateRangeType">
+            <tag name="form.type" alias="sonata_type_date_range" />
+
+            <argument type="service" id="translator" />
+        </service>
 
         <!-- Form Extension -->
         <service id="sonata.admin.form.extension.field" class="Sonata\AdminBundle\Form\Extension\Field\Type\FormTypeFieldExtension">

+ 1 - 8
Resources/views/CRUD/base_list.html.twig

@@ -153,14 +153,7 @@ file that was distributed with this source code.
                                         <tr id="filter_{{ filter.name }}_row">
                                             <td class="filter-title">{{ admin.trans(filter.label) }}</td>
                                             <td class="filter-type">{{ form_widget(form.getChild(filter.name).getChild('type')) }}</td>
-                                            <td class="filter-value">
-                                                {{ form_widget(form.getChild(filter.name).getChild('value')) }}
-                                                    
-                                                {% if form.getChild(filter.name).getChildren()['valueb'] is defined %}
-                                                    {{ form_widget(form.getChild(filter.name).getChild('valueb')) }}
-                                                {% endif %}
-
-                                            </td>
+                                            <td class="filter-value">{{ form_widget(form.getChild(filter.name).getChild('value')) }}</td>
                                         </tr>
                                     {% endfor %}
                                 </table>