Skip to content

Commit

Permalink
Added to TimeType extension possibility to render form as `single_t…
Browse files Browse the repository at this point in the history
…ext` (similar to DateType option) (issue #1205)

Adjusted `DateTimeType` to allow usage of this new feature
  • Loading branch information
stloyd committed Jun 23, 2011
1 parent 59f85b4 commit 17b41b2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
Expand Up @@ -99,7 +99,7 @@
{% block time_widget %}
{% spaceless %}
{% if widget == 'single_text' %}
{{ block('field_widget') }}
{{ block('text_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 %}
Expand Down
6 changes: 2 additions & 4 deletions src/Symfony/Component/Form/Extension/Core/Type/TimeType.php
Expand Up @@ -31,8 +31,7 @@ public function buildForm(FormBuilder $builder, array $options)
if ($options['widget'] === 'single_text') {
$builder->appendClientTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['user_timezone'], 'H:i:s'));
} 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']);
if (is_array($options['empty_value'])) { $options['empty_value'] = array_merge(array('hour' => null, 'minute' => null, 'second' => null), $options['empty_value']);
} else {
$options['empty_value'] = array('hour' => $options['empty_value'], 'minute' => $options['empty_value'], 'second' => $options['empty_value']);
}
Expand Down Expand Up @@ -66,10 +65,9 @@ public function buildForm(FormBuilder $builder, array $options)
}

$parts = array('hour', 'minute');
if ($options['with_seconds']) {
if ($options['with_seconds']) { if ($options['with_seconds']) {
$parts[] = 'second';
}

if ($options['input'] === 'string') {
$builder->appendNormTransformer(new ReversedTransformer(
new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], 'H:i:s')
Expand Down

0 comments on commit 17b41b2

Please sign in to comment.