当前位置: 首页>>代码示例>>PHP>>正文


PHP FormBuilder::appendClientTransformer方法代码示例

本文整理汇总了PHP中Symfony\Component\Form\FormBuilder::appendClientTransformer方法的典型用法代码示例。如果您正苦于以下问题:PHP FormBuilder::appendClientTransformer方法的具体用法?PHP FormBuilder::appendClientTransformer怎么用?PHP FormBuilder::appendClientTransformer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Form\FormBuilder的用法示例。


在下文中一共展示了FormBuilder::appendClientTransformer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     if ($options['choice_list'] && !$options['choice_list'] instanceof ChoiceListInterface) {
         throw new FormException('The "choice_list" must be an instance of "Symfony\\Component\\Form\\Extension\\Core\\ChoiceList\\ChoiceListInterface".');
     }
     if (!$options['choice_list']) {
         $options['choice_list'] = new ArrayChoiceList($options['choices']);
     }
     if ($options['expanded']) {
         // Load choices already if expanded
         $choices = $options['choice_list']->getChoices();
         // Flatten choices
         $flattened = array();
         foreach ($choices as $value => $choice) {
             if (is_array($choice)) {
                 $flattened = array_replace($flattened, $choice);
             } else {
                 $flattened[$value] = $choice;
             }
         }
         $options['choices'] = $flattened;
         foreach ($options['choices'] as $choice => $value) {
             if ($options['multiple']) {
                 $builder->add((string) $choice, 'checkbox', array('value' => $choice, 'label' => $value, 'required' => false));
             } else {
                 $builder->add((string) $choice, 'radio', array('value' => $choice, 'label' => $value));
             }
         }
     }
     // empty value
     if ($options['multiple'] || $options['expanded']) {
         // never use and empty value for these cases
         $emptyValue = null;
     } elseif (false === $options['empty_value']) {
         // an empty value should be added but the user decided otherwise
         $emptyValue = null;
     } elseif (null === $options['empty_value']) {
         // user did not made a decision, so we put a blank empty value
         $emptyValue = $options['required'] ? null : '';
     } else {
         // empty value has been set explicitly
         $emptyValue = $options['empty_value'];
     }
     $builder->setAttribute('choice_list', $options['choice_list'])->setAttribute('preferred_choices', $options['preferred_choices'])->setAttribute('multiple', $options['multiple'])->setAttribute('expanded', $options['expanded'])->setAttribute('required', $options['required'])->setAttribute('empty_value', $emptyValue);
     if ($options['expanded']) {
         if ($options['multiple']) {
             $builder->appendClientTransformer(new ArrayToBooleanChoicesTransformer($options['choice_list']));
         } else {
             $builder->appendClientTransformer(new ScalarToBooleanChoicesTransformer($options['choice_list']))->addEventSubscriber(new FixRadioInputListener(), 10);
         }
     } else {
         if ($options['multiple']) {
             $builder->appendClientTransformer(new ArrayToChoicesTransformer());
         } else {
             $builder->appendClientTransformer(new ScalarToChoiceTransformer());
         }
     }
 }
开发者ID:usefulthink,项目名称:symfony,代码行数:61,代码来源:ChoiceType.php

示例2: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     $parts = array('hour', 'minute');
     $format = 'H:i';
     if ($options['with_seconds']) {
         $format = 'H:i:s';
         $parts[] = 'second';
     }
     if ('single_text' === $options['widget']) {
         $builder->appendClientTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['user_timezone'], $format));
     } else {
         $hourOptions = $minuteOptions = $secondOptions = array();
         if ('choice' === $options['widget']) {
             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']);
             }
             $hours = $minutes = array();
             foreach ($options['hours'] as $hour) {
                 $hours[$hour] = str_pad($hour, 2, '0', STR_PAD_LEFT);
             }
             foreach ($options['minutes'] as $minute) {
                 $minutes[$minute] = str_pad($minute, 2, '0', STR_PAD_LEFT);
             }
             // Only pass a subset of the options to children
             $hourOptions = array('choices' => $hours, 'empty_value' => $options['empty_value']['hour']);
             $minuteOptions = array('choices' => $minutes, 'empty_value' => $options['empty_value']['minute']);
             if ($options['with_seconds']) {
                 $seconds = array();
                 foreach ($options['seconds'] as $second) {
                     $seconds[$second] = str_pad($second, 2, '0', STR_PAD_LEFT);
                 }
                 $secondOptions = array('choices' => $seconds, 'empty_value' => $options['empty_value']['second']);
             }
             // Append generic carry-along options
             foreach (array('required', 'translation_domain') as $passOpt) {
                 $hourOptions[$passOpt] = $minuteOptions[$passOpt] = $options[$passOpt];
                 if ($options['with_seconds']) {
                     $secondOptions[$passOpt] = $options[$passOpt];
                 }
             }
         }
         $builder->add('hour', $options['widget'], $hourOptions)->add('minute', $options['widget'], $minuteOptions);
         if ($options['with_seconds']) {
             $builder->add('second', $options['widget'], $secondOptions);
         }
         $builder->appendClientTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], $parts, 'text' === $options['widget']));
     }
     if ('string' === $options['input']) {
         $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], 'H:i:s')));
     } elseif ('timestamp' === $options['input']) {
         $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['data_timezone'], $options['data_timezone'])));
     } elseif ('array' === $options['input']) {
         $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['data_timezone'], $parts)));
     }
     $builder->setAttribute('widget', $options['widget'])->setAttribute('with_seconds', $options['with_seconds']);
 }
开发者ID:richardmiller,项目名称:symfony,代码行数:61,代码来源:TimeType.php

示例3: buildForm

    public function buildForm(FormBuilder $builder, array $options)
    {
        if (!$options['choices'] && !$options['choice_list']) {
            throw new FormException('Either the option "choices" or "choice_list" is required');
        }

        if ($options['choice_list'] && !$options['choice_list'] instanceof ChoiceListInterface) {
            throw new FormException('The "choice_list" must be an instance of "Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface".');
        }

        if (!$options['choice_list']) {
            $options['choice_list'] = new ArrayChoiceList($options['choices']);
        }

        if ($options['expanded']) {
            // Load choices already if expanded
            $options['choices'] = $options['choice_list']->getChoices();

            foreach ($options['choices'] as $choice => $value) {
                if ($options['multiple']) {
                    $builder->add((string)$choice, 'checkbox', array(
                        'value' => $choice,
                        'label' => $value,
                        // The user can check 0 or more checkboxes. If required
                        // is true, he is required to check all of them.
                        'required' => false,
                    ));
                } else {
                    $builder->add((string)$choice, 'radio', array(
                        'value' => $choice,
                        'label' => $value,
                    ));
                }
            }
        }

        $builder->setAttribute('choice_list', $options['choice_list'])
            ->setAttribute('preferred_choices', $options['preferred_choices'])
            ->setAttribute('multiple', $options['multiple'])
            ->setAttribute('expanded', $options['expanded']);

        if ($options['expanded']) {
            if ($options['multiple']) {
                $builder->appendClientTransformer(new ArrayToBooleanChoicesTransformer($options['choice_list']));
            } else {
                $builder->appendClientTransformer(new ScalarToBooleanChoicesTransformer($options['choice_list']));
                $builder->addEventSubscriber(new FixRadioInputListener(), 10);
            }
        } else {
            if ($options['multiple']) {
                $builder->appendClientTransformer(new ArrayToChoicesTransformer());
            } else {
                $builder->appendClientTransformer(new ScalarToChoiceTransformer());
            }
        }

    }
开发者ID:nacef,项目名称:symfony,代码行数:57,代码来源:ChoiceType.php

示例4: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     $parts = array('year', 'month', 'day', 'hour', 'minute');
     $timeParts = array('hour', 'minute');
     $format = 'Y-m-d H:i:00';
     if ($options['with_seconds']) {
         $format = 'Y-m-d H:i:s';
         $parts[] = 'second';
         $timeParts[] = 'second';
     }
     if ($options['date_widget'] !== $options['time_widget']) {
         throw new FormException(sprintf('Options "date_widget" and "time_widget" need to be identical. Used: "date_widget" = "%s" and "time_widget" = "%s".', $options['date_widget'] ?: 'choice', $options['time_widget'] ?: 'choice'));
     }
     if ($options['widget'] === 'single_text') {
         $builder->appendClientTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['user_timezone'], $format));
     } else {
         // Only pass a subset of the options to children
         $dateOptions = array_intersect_key($options, array_flip(array('years', 'months', 'days', 'empty_value', 'required', 'invalid_message', 'invalid_message_parameters', 'translation_domain')));
         $timeOptions = array_intersect_key($options, array_flip(array('hours', 'minutes', 'seconds', 'with_seconds', 'empty_value', 'required', 'invalid_message', 'invalid_message_parameters', 'translation_domain')));
         // If `widget` is set, overwrite widget options from `date` and `time`
         if (isset($options['widget'])) {
             $dateOptions['widget'] = $options['widget'];
             $timeOptions['widget'] = $options['widget'];
         } else {
             if (isset($options['date_widget'])) {
                 $dateOptions['widget'] = $options['date_widget'];
             }
             if (isset($options['time_widget'])) {
                 $timeOptions['widget'] = $options['time_widget'];
             }
         }
         if (isset($options['date_format'])) {
             $dateOptions['format'] = $options['date_format'];
         }
         $dateOptions['input'] = 'array';
         $timeOptions['input'] = 'array';
         $builder->appendClientTransformer(new DataTransformerChain(array(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], $parts), new ArrayToPartsTransformer(array('date' => array('year', 'month', 'day'), 'time' => $timeParts)))))->add('date', 'date', $dateOptions)->add('time', 'time', $timeOptions);
     }
     if ($options['input'] === 'string') {
         $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], $format)));
     } else {
         if ($options['input'] === 'timestamp') {
             $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['data_timezone'], $options['data_timezone'])));
         } else {
             if ($options['input'] === 'array') {
                 $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['data_timezone'], $parts)));
             }
         }
     }
     $builder->setAttribute('widget', $options['widget']);
 }
开发者ID:rcambien,项目名称:symfony,代码行数:54,代码来源:DateTimeType.php

示例5: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     $formatter = new \IntlDateFormatter(\Locale::getDefault(), $options['format'], \IntlDateFormatter::NONE, \DateTimeZone::UTC);
     if ($options['widget'] === 'single_text') {
         $builder->appendClientTransformer(new DateTimeToLocalizedStringTransformer($options['data_timezone'], $options['user_timezone'], $options['format'], \IntlDateFormatter::NONE));
     } else {
         $yearOptions = $monthOptions = $dayOptions = array();
         if ($options['widget'] === 'choice') {
             if (is_array($options['empty_value'])) {
                 $options['empty_value'] = array_merge(array('year' => null, 'month' => null, 'day' => null), $options['empty_value']);
             } else {
                 $options['empty_value'] = array('year' => $options['empty_value'], 'month' => $options['empty_value'], 'day' => $options['empty_value']);
             }
             // Only pass a subset of the options to children
             $yearOptions = array('choice_list' => new PaddedChoiceList(array_combine($options['years'], $options['years']), 4, '0', STR_PAD_LEFT), 'empty_value' => $options['empty_value']['year'], 'required' => $options['required']);
             $monthOptions = array('choice_list' => new MonthChoiceList($formatter, $options['months']), 'empty_value' => $options['empty_value']['month'], 'required' => $options['required']);
             $dayOptions = array('choice_list' => new PaddedChoiceList(array_combine($options['days'], $options['days']), 2, '0', STR_PAD_LEFT), 'empty_value' => $options['empty_value']['day'], 'required' => $options['required']);
         }
         $builder->add('year', $options['widget'], $yearOptions)->add('month', $options['widget'], $monthOptions)->add('day', $options['widget'], $dayOptions)->appendClientTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], array('year', 'month', 'day')));
     }
     if ($options['input'] === 'string') {
         $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], 'Y-m-d')));
     } else {
         if ($options['input'] === 'timestamp') {
             $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['data_timezone'], $options['data_timezone'])));
         } else {
             if ($options['input'] === 'array') {
                 $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['data_timezone'], array('year', 'month', 'day'))));
             }
         }
     }
     $builder->setAttribute('formatter', $formatter)->setAttribute('widget', $options['widget']);
 }
开发者ID:nightchiller,项目名称:symfony,代码行数:36,代码来源:DateType.php

示例6: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     // Overwrite required option for child fields
     $options['first_options']['required'] = $options['required'];
     $options['second_options']['required'] = $options['required'];
     $builder->appendClientTransformer(new ValueToDuplicatesTransformer(array($options['first_name'], $options['second_name'])))->add($options['first_name'], $options['type'], array_merge($options['options'], $options['first_options']))->add($options['second_name'], $options['type'], array_merge($options['options'], $options['second_options']));
 }
开发者ID:rouffj,项目名称:symfony,代码行数:10,代码来源:RepeatedType.php

示例7: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     if (!$options['choice_list']) {
         $options['choice_list'] = new AjaxArrayChoiceList($options['choices'], $options['ajax']);
     }
     $builder->appendClientTransformer(new ChoiceToJsonTransformer($options['choice_list'], $options['widget'], $options['multiple'], $options['ajax'], $options['freeValues']))->setAttribute('choice_list', $options['choice_list'])->setAttribute('widget', $options['widget'])->setAttribute('route_name', $options['route_name'])->setAttribute('freeValues', $options['freeValues']);
 }
开发者ID:raziel057,项目名称:GenemuFormBundle,代码行数:10,代码来源:AutocompleterType.php

示例8: buildForm

 public function buildForm(FormBuilder $builder, array $options)
 {
     $hourOptions = $minuteOptions = $secondOptions = array();
     $parts = array('hour', 'minute');
     if ($options['widget'] === 'choice') {
         $hourOptions['choice_list'] = new PaddedChoiceList(array_combine($options['hours'], $options['hours']), 2, '0', STR_PAD_LEFT);
         $minuteOptions['choice_list'] = new PaddedChoiceList(array_combine($options['minutes'], $options['minutes']), 2, '0', STR_PAD_LEFT);
         if ($options['with_seconds']) {
             $secondOptions['choice_list'] = new PaddedChoiceList(array_combine($options['seconds'], $options['seconds']), 2, '0', STR_PAD_LEFT);
         }
     }
     $builder->add('hour', $options['widget'], $hourOptions)->add('minute', $options['widget'], $minuteOptions);
     if ($options['with_seconds']) {
         $parts[] = 'second';
         $builder->add('second', $options['widget'], $secondOptions);
     }
     if ($options['input'] === 'string') {
         $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], 'H:i:s')));
     } else {
         if ($options['input'] === 'timestamp') {
             $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['data_timezone'], $options['data_timezone'])));
         } else {
             if ($options['input'] === 'array') {
                 $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['data_timezone'], $parts)));
             }
         }
     }
     $builder->appendClientTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], $parts, $options['widget'] === 'text'))->setAttribute('widget', $options['widget'])->setAttribute('with_seconds', $options['with_seconds']);
 }
开发者ID:rfc1483,项目名称:blog,代码行数:29,代码来源:TimeType.php

示例9: buildForm

 public function buildForm(FormBuilder $builder, array $options)
 {
     $formatter = new \IntlDateFormatter(\Locale::getDefault(), $options['format'], \IntlDateFormatter::NONE, \DateTimeZone::UTC);
     if ($options['widget'] === 'single-text') {
         $builder->appendClientTransformer(new DateTimeToLocalizedStringTransformer($options['data_timezone'], $options['user_timezone'], $options['format'], \IntlDateFormatter::NONE));
     } else {
         $yearOptions = $monthOptions = $dayOptions = array();
         $widget = $options['widget'];
         if ($widget === 'choice') {
             // Only pass a subset of the options to children
             $yearOptions = array('choice_list' => new PaddedChoiceList(array_combine($options['years'], $options['years']), 4, '0', STR_PAD_LEFT));
             $monthOptions = array('choice_list' => new MonthChoiceList($formatter, $options['months']));
             $dayOptions = array('choice_list' => new PaddedChoiceList(array_combine($options['days'], $options['days']), 2, '0', STR_PAD_LEFT));
         }
         $builder->add('year', $widget, $yearOptions)->add('month', $widget, $monthOptions)->add('day', $widget, $dayOptions)->appendClientTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], array('year', 'month', 'day')));
     }
     if ($options['input'] === 'string') {
         $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], 'Y-m-d')));
     } else {
         if ($options['input'] === 'timestamp') {
             $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['data_timezone'], $options['data_timezone'])));
         } else {
             if ($options['input'] === 'array') {
                 $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['data_timezone'], array('year', 'month', 'day'))));
             } else {
                 if ($options['input'] !== 'datetime') {
                     throw new FormException('The "input" option must be "datetime", "string", "timestamp" or "array".');
                 }
             }
         }
     }
     $builder->setAttribute('formatter', $formatter)->setAttribute('widget', $options['widget']);
 }
开发者ID:rfc1483,项目名称:symfony,代码行数:33,代码来源:DateType.php

示例10: buildForm

 public function buildForm(FormBuilder $builder, array $options)
 {
     // Only pass a subset of the options to children
     $dateOptions = array_intersect_key($options, array_flip(array('years', 'months', 'days')));
     $timeOptions = array_intersect_key($options, array_flip(array('hours', 'minutes', 'seconds', 'with_seconds')));
     if (isset($options['date_widget'])) {
         $dateOptions['widget'] = $options['date_widget'];
     }
     if (isset($options['date_format'])) {
         $dateOptions['format'] = $options['date_format'];
     }
     $dateOptions['input'] = 'array';
     if (isset($options['time_widget'])) {
         $timeOptions['widget'] = $options['time_widget'];
     }
     $timeOptions['input'] = 'array';
     $parts = array('year', 'month', 'day', 'hour', 'minute');
     $timeParts = array('hour', 'minute');
     if ($options['with_seconds']) {
         $parts[] = 'second';
         $timeParts[] = 'second';
     }
     $builder->appendClientTransformer(new DataTransformerChain(array(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], $parts), new ArrayToPartsTransformer(array('date' => array('year', 'month', 'day'), 'time' => $timeParts)))))->add('date', 'date', $dateOptions)->add('time', 'time', $timeOptions);
     if ($options['input'] === 'string') {
         $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], 'Y-m-d H:i:s')));
     } else {
         if ($options['input'] === 'timestamp') {
             $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['data_timezone'], $options['data_timezone'])));
         } else {
             if ($options['input'] === 'array') {
                 $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['data_timezone'], $parts)));
             }
         }
     }
 }
开发者ID:rfc1483,项目名称:blog,代码行数:35,代码来源:DateTimeType.php

示例11: buildForm

 public function buildForm(FormBuilder $builder, array $options)
 {
     $builder->appendClientTransformer(new ValueToDuplicatesTransformer(array(
             $options['first_name'],
             $options['second_name'],
         )))
         ->add($options['first_name'], $options['type'], $options['options'])
         ->add($options['second_name'], $options['type'], $options['options']);
 }
开发者ID:nacef,项目名称:symfony,代码行数:9,代码来源:RepeatedType.php

示例12: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     $parts = array('hour', 'minute');
     $format = 'H:i:00';
     if ($options['with_seconds']) {
         $format = 'H:i:s';
         $parts[] = 'second';
     }
     if ($options['widget'] === 'single_text') {
         $builder->appendClientTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['user_timezone'], $format));
     } else {
         $hourOptions = $minuteOptions = $secondOptions = array();
         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 {
                 $options['empty_value'] = array('hour' => $options['empty_value'], 'minute' => $options['empty_value'], 'second' => $options['empty_value']);
             }
             // Only pass a subset of the options to children
             $hourOptions = array('choice_list' => new PaddedChoiceList(array_combine($options['hours'], $options['hours']), 2, '0', STR_PAD_LEFT), 'empty_value' => $options['empty_value']['hour'], 'required' => $options['required']);
             $minuteOptions = array('choice_list' => new PaddedChoiceList(array_combine($options['minutes'], $options['minutes']), 2, '0', STR_PAD_LEFT), 'empty_value' => $options['empty_value']['minute'], 'required' => $options['required']);
             if ($options['with_seconds']) {
                 $secondOptions = array('choice_list' => new PaddedChoiceList(array_combine($options['seconds'], $options['seconds']), 2, '0', STR_PAD_LEFT), 'empty_value' => $options['empty_value']['second'], 'required' => $options['required']);
             }
         }
         $builder->add('hour', $options['widget'], $hourOptions)->add('minute', $options['widget'], $minuteOptions);
         if ($options['with_seconds']) {
             $builder->add('second', $options['widget'], $secondOptions);
         }
         $builder->appendClientTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], $parts, $options['widget'] === 'text'));
     }
     if ($options['input'] === 'string') {
         $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], $format)));
     } else {
         if ($options['input'] === 'timestamp') {
             $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['data_timezone'], $options['data_timezone'])));
         } else {
             if ($options['input'] === 'array') {
                 $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['data_timezone'], $parts)));
             }
         }
     }
     $builder->setAttribute('widget', $options['widget'])->setAttribute('with_seconds', $options['with_seconds']);
 }
开发者ID:robertowest,项目名称:CuteFlow-V4,代码行数:47,代码来源:TimeType.php

示例13: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     $format = $options['format'];
     $pattern = null;
     $allowedFormatOptionValues = array(\IntlDateFormatter::FULL, \IntlDateFormatter::LONG, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT);
     // If $format is not in the allowed options, it's considered as the pattern of the formatter if it is a string
     if (!in_array($format, $allowedFormatOptionValues, true)) {
         if (is_string($format)) {
             $defaultOptions = $this->getDefaultOptions($options);
             $format = $defaultOptions['format'];
             $pattern = $options['format'];
         } else {
             throw new CreationException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom pattern');
         }
     }
     $formatter = new \IntlDateFormatter(\Locale::getDefault(), $format, \IntlDateFormatter::NONE, 'UTC', \IntlDateFormatter::GREGORIAN, $pattern);
     if ('single_text' === $options['widget']) {
         $builder->appendClientTransformer(new DateTimeToLocalizedStringTransformer($options['data_timezone'], $options['user_timezone'], $format, \IntlDateFormatter::NONE, \IntlDateFormatter::GREGORIAN, $pattern));
     } else {
         $yearOptions = $monthOptions = $dayOptions = array();
         if ('choice' === $options['widget']) {
             if (is_array($options['empty_value'])) {
                 $options['empty_value'] = array_merge(array('year' => null, 'month' => null, 'day' => null), $options['empty_value']);
             } else {
                 $options['empty_value'] = array('year' => $options['empty_value'], 'month' => $options['empty_value'], 'day' => $options['empty_value']);
             }
             $years = $months = $days = array();
             foreach ($options['years'] as $year) {
                 $years[$year] = str_pad($year, 4, '0', STR_PAD_LEFT);
             }
             foreach ($options['months'] as $month) {
                 $months[$month] = str_pad($month, 2, '0', STR_PAD_LEFT);
             }
             foreach ($options['days'] as $day) {
                 $days[$day] = str_pad($day, 2, '0', STR_PAD_LEFT);
             }
             // Only pass a subset of the options to children
             $yearOptions = array('choices' => $years, 'value_strategy' => ChoiceList::COPY_CHOICE, 'index_strategy' => ChoiceList::COPY_CHOICE, 'empty_value' => $options['empty_value']['year']);
             $monthOptions = array('choices' => $this->formatMonths($formatter, $months), 'value_strategy' => ChoiceList::COPY_CHOICE, 'index_strategy' => ChoiceList::COPY_CHOICE, 'empty_value' => $options['empty_value']['month']);
             $dayOptions = array('choices' => $days, 'value_strategy' => ChoiceList::COPY_CHOICE, 'index_strategy' => ChoiceList::COPY_CHOICE, 'empty_value' => $options['empty_value']['day']);
             // Append generic carry-along options
             foreach (array('required', 'translation_domain') as $passOpt) {
                 $yearOptions[$passOpt] = $monthOptions[$passOpt] = $dayOptions[$passOpt] = $options[$passOpt];
             }
         }
         $builder->add('year', $options['widget'], $yearOptions)->add('month', $options['widget'], $monthOptions)->add('day', $options['widget'], $dayOptions)->appendClientTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], array('year', 'month', 'day')));
     }
     if ('string' === $options['input']) {
         $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], 'Y-m-d')));
     } elseif ('timestamp' === $options['input']) {
         $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['data_timezone'], $options['data_timezone'])));
     } elseif ('array' === $options['input']) {
         $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['data_timezone'], array('year', 'month', 'day'))));
     }
     $builder->setAttribute('formatter', $formatter)->setAttribute('widget', $options['widget']);
 }
开发者ID:netconstructor,项目名称:symfony,代码行数:59,代码来源:DateType.php

示例14: buildForm

 public function buildForm(FormBuilder $builder, array $options)
 {
     if (!$options['userIsRegistered']) {
         $builder->add('author_name')->add('author_email');
     }
     $builder->add('title')->add('description')->add('content')->add('recaptcha', 'ewz_recaptcha');
     if (null !== $this->tagTransformer) {
         $builder->appendClientTransformer($this->tagTransformer);
     }
 }
开发者ID:bamper,项目名称:symfony2pros.com,代码行数:10,代码来源:TutorialType.php

示例15: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     $format = $options['format'];
     $pattern = null;
     $allowedFormatOptionValues = array(\IntlDateFormatter::FULL, \IntlDateFormatter::LONG, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT);
     // If $format is not in the allowed options, it's considered as the pattern of the formatter if it is a string
     if (!in_array($format, $allowedFormatOptionValues, true)) {
         if (is_string($format)) {
             $defaultOptions = $this->getDefaultOptions($options);
             $format = $defaultOptions['format'];
             $pattern = $options['format'];
         } else {
             throw new CreationException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom pattern');
         }
     }
     $formatter = new \IntlDateFormatter(\Locale::getDefault(), $format, \IntlDateFormatter::NONE, \DateTimeZone::UTC, \IntlDateFormatter::GREGORIAN, $pattern);
     if ($options['widget'] === 'single_text') {
         $builder->appendClientTransformer(new DateTimeToLocalizedStringTransformer($options['data_timezone'], $options['user_timezone'], $format, \IntlDateFormatter::NONE, \IntlDateFormatter::GREGORIAN, $pattern));
     } else {
         $yearOptions = $monthOptions = $dayOptions = array();
         if ($options['widget'] === 'choice') {
             if (is_array($options['empty_value'])) {
                 $options['empty_value'] = array_merge(array('year' => null, 'month' => null, 'day' => null), $options['empty_value']);
             } else {
                 $options['empty_value'] = array('year' => $options['empty_value'], 'month' => $options['empty_value'], 'day' => $options['empty_value']);
             }
             // Only pass a subset of the options to children
             $yearOptions = array('choice_list' => new PaddedChoiceList(array_combine($options['years'], $options['years']), 4, '0', STR_PAD_LEFT), 'empty_value' => $options['empty_value']['year'], 'required' => $options['required']);
             $monthOptions = array('choice_list' => new MonthChoiceList($formatter, $options['months']), 'empty_value' => $options['empty_value']['month'], 'required' => $options['required']);
             $dayOptions = array('choice_list' => new PaddedChoiceList(array_combine($options['days'], $options['days']), 2, '0', STR_PAD_LEFT), 'empty_value' => $options['empty_value']['day'], 'required' => $options['required']);
         }
         $builder->add('year', $options['widget'], $yearOptions)->add('month', $options['widget'], $monthOptions)->add('day', $options['widget'], $dayOptions)->appendClientTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], array('year', 'month', 'day')));
     }
     if ($options['input'] === 'string') {
         $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], 'Y-m-d')));
     } else {
         if ($options['input'] === 'timestamp') {
             $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['data_timezone'], $options['data_timezone'])));
         } else {
             if ($options['input'] === 'array') {
                 $builder->appendNormTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['data_timezone'], array('year', 'month', 'day'))));
             }
         }
     }
     $builder->setAttribute('formatter', $formatter)->setAttribute('widget', $options['widget']);
 }
开发者ID:netcon-source,项目名称:prontotype,代码行数:49,代码来源:DateType.php


注:本文中的Symfony\Component\Form\FormBuilder::appendClientTransformer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。