Exemplo n.º 1
0
 /**
  * {@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());
         }
     }
 }
Exemplo n.º 2
0
 /**
  * {@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']);
 }
Exemplo n.º 3
0
    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());
            }
        }

    }
Exemplo n.º 4
0
 /**
  * {@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']);
 }
Exemplo n.º 5
0
 /**
  * {@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']);
 }
Exemplo n.º 6
0
 /**
  * {@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']));
 }
 /**
  * {@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']);
 }
Exemplo n.º 8
0
 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']);
 }
Exemplo n.º 9
0
 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']);
 }
Exemplo n.º 10
0
 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)));
             }
         }
     }
 }
Exemplo n.º 11
0
 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']);
 }
Exemplo n.º 12
0
 /**
  * {@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']);
 }
Exemplo n.º 13
0
 /**
  * {@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']);
 }
Exemplo n.º 14
0
 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);
     }
 }
Exemplo n.º 15
0
 /**
  * {@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']);
 }
Exemplo n.º 16
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     if (true === empty($options['choice_list'])) {
         $options['choice_list'] = new AjaxArrayChoiceList($options['choices'], $options['ajax']);
     }
     if (isset($options['tokenLimit']) && is_numeric($options['tokenLimit']) && $options['tokenLimit'] > 0) {
         $options['multiple'] = 1 != $options['tokenLimit'];
     }
     if (!$options['multiple']) {
         $options['tokenLimit'] = 1;
     }
     $builder->appendClientTransformer(new ChoiceToJsonTransformer($options['choice_list'], $options['widget'], $options['multiple'], $options['ajax']))->setAttribute('choice_list', $options['choice_list'])->setAttribute('widget', $options['widget'])->setAttribute('route_name', $options['route_name']);
     foreach ($this->_availableTokeninputOptions as $option) {
         if (isset($options[$option])) {
             $builder->setAttribute($option, $options[$option]);
         }
     }
 }
Exemplo n.º 17
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     $builder->appendClientTransformer(new BooleanToStringTransformer())->setAttribute('value', $options['value']);
 }
Exemplo n.º 18
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     $builder->appendClientTransformer(new IntegerToLocalizedStringTransformer($options['precision'], $options['grouping'], $options['rounding_mode']));
 }
Exemplo n.º 19
0
 public function buildForm(FormBuilder $builder, array $options)
 {
     $transformer = new ChoicesToTextTransformer();
     $builder->appendClientTransformer($transformer);
 }
Exemplo n.º 20
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     $builder->appendClientTransformer(new MoneyToLocalizedStringTransformer($options['precision'], $options['grouping'], null, $options['divisor']))->setAttribute('currency', $options['currency']);
 }
Exemplo n.º 21
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     $builder->appendClientTransformer(new PercentToLocalizedStringTransformer($options['precision'], $options['type']));
 }
Exemplo n.º 22
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     $builder->appendClientTransformer(new ValueToStringTransformer());
 }
Exemplo n.º 23
0
 public function buildForm(FormBuilder $builder, array $options)
 {
     $builder->appendClientTransformer($this->usernameTransformer);
 }