浏览代码

Sync with master and clean up

stloyd 14 年之前
父节点
当前提交
4e3406d633

+ 1 - 1
src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

@@ -99,7 +99,7 @@
 {% block time_widget %}
 {% spaceless %}
     {% if widget == 'single_text' %}
-        {{ block('text_widget') }}
+        {{ 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 %}

+ 2 - 9
src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/time_widget.html.php

@@ -1,14 +1,7 @@
 <?php if ($widget == 'single_text'): ?>
-    <input type="text"
-        <?php echo $view['form']->renderBlock('attributes') ?>
-        name="<?php echo $view->escape($full_name) ?>"
-        value="<?php echo $view->escape($value) ?>"
-        <?php if ($read_only): ?>disabled="disabled"<?php endif ?>
-        <?php if ($required): ?>required="required"<?php endif ?>
-        <?php if ($max_length): ?>maxlength="<?php echo $max_length ?>"<?php endif ?>
-    />
+    <?php echo $view['form']->renderBlock('field_widget'); ?>
 <?php else: ?>
-    <div<?php echo $view['form']->renderBlock('container_attributes') ?>>
+    <div <?php echo $view['form']->renderBlock('container_attributes') ?>>
         <?php
             // There should be no spaces between the colons and the widgets, that's why
             // this block is written in a single PHP tag

+ 14 - 12
src/Symfony/Component/Form/Extension/Core/Type/TimeType.php

@@ -28,14 +28,9 @@ class TimeType extends AbstractType
      */
     public function buildForm(FormBuilder $builder, array $options)
     {
-        $parts = array('hour', 'minute');
-        if ($options['with_seconds']) {
-            $parts[] = 'second';
-        }
-
         if ($options['widget'] === 'single_text') {
             $builder->appendClientTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['user_timezone'], 'H:i:s'));
-        } else {
+        } else if ($options['widget'] === 'choice') {
             if (is_array($options['empty_value'])) {
                 $options['empty_value'] = array_merge(array('hour' => null, 'minute' => null, 'second' => null), $options['empty_value']);
             } else {
@@ -68,13 +63,11 @@ class TimeType extends AbstractType
                     'required' => $options['required'],
                 ));
             }
+        }
 
-            $builder->appendClientTransformer(new DateTimeToArrayTransformer(
-                $options['data_timezone'],
-                $options['user_timezone'],
-                $parts,
-                $options['widget'] === 'text'
-            ));
+        $parts = array('hour', 'minute');
+        if ($options['with_seconds']) {
+            $parts[] = 'second';
         }
 
         if ($options['input'] === 'string') {
@@ -91,6 +84,15 @@ class TimeType extends AbstractType
             ));
         }
 
+        if ($options['widget'] !== 'single_text') {
+            $builder->appendClientTransformer(new DateTimeToArrayTransformer(
+                $options['data_timezone'],
+                $options['user_timezone'],
+                $parts,
+                $options['widget'] === 'text'
+            ));
+        }
+
         $builder
             ->setAttribute('widget', $options['widget'])
             ->setAttribute('with_seconds', $options['with_seconds'])

+ 18 - 1
tests/Symfony/Tests/Component/Form/AbstractLayoutTest.php

@@ -1503,7 +1503,24 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
         );
     }
 
-    public function testTimeSingleText()    {        $form = $this->factory->createNamed('time', 'na&me', '04:05:06', array(            'property_path' => 'name',            'input' => 'string',            'widget' => 'single_text',        ));        $this->assertWidgetMatchesXpath($form->createView(), array(),'/input    [@type="text"]    [@name="na&me"]    [@value="04:05:06"]    [@id="my&id"]    [@class="my&class"]'        );    }    public function testTimeWithEmptyValueGlobal()
+    public function testTimeSingleText()
+    {
+        $form = $this->factory->createNamed('time', 'na&me', '04:05:06', array(
+            'property_path' => 'name',
+            'input' => 'string',
+            'widget' => 'single_text',
+        ));
+
+        $this->assertWidgetMatchesXpath($form->createView(), array(),
+'/input
+    [@type="text"]
+    [@name="na&me"]
+    [@value="04:05:06"]
+'
+        );
+    }
+
+    public function testTimeWithEmptyValueGlobal()
     {
         $form = $this->factory->createNamed('time', 'na&me', null, array(
             'property_path' => 'name',