public function buildForm(FormBuilder $builder, array $options)
    {
        $sonataAdmin = array(
            'name'      => null,
            'admin'     => null,
            'value'     => null,
            'edit'      => 'standard',
            'inline'    => 'natural',
            'field_description' => null,
            'block_name' => false
        );

        $builder->setAttribute('sonata_admin_enabled', false);

        if ($options['sonata_field_description'] instanceof FieldDescriptionInterface) {
            $fieldDescription = $options['sonata_field_description'];

            $sonataAdmin['admin']             = $fieldDescription->getAdmin();
            $sonataAdmin['field_description'] = $fieldDescription;
            $sonataAdmin['name']              = $fieldDescription->getName();
            $sonataAdmin['edit']              = $fieldDescription->getOption('edit', 'standard');
            $sonataAdmin['inline']            = $fieldDescription->getOption('inline', 'natural');

            $builder->setAttribute('sonata_admin_enabled', true);
        }

        $builder->setAttribute('sonata_admin', $sonataAdmin);
    }
 protected function getBuilder($name = 'name', $propertyPath = null)
 {
     $builder = new FormBuilder($name, $this->factory, $this->dispatcher);
     $builder->setAttribute('property_path', new PropertyPath($propertyPath ?: $name));
     $builder->setAttribute('error_mapping', array());
     return $builder;
 }
 public function buildForm(FormBuilder $builder, array $options)
 {
     $builder->setAttribute('url', $options['url']);
     $builder->setAttribute('url_params', $options['url_params']);
     $builder->setAttribute('callback', $options['callback']);
     $builder->setAttribute('select_callback', $options['select_callback']);
     parent::buildForm($builder, $options);
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     $changemonth = $options['changeMonth'];
     $changeyear = $options['changeYear'];
     $mindate = $options['minDate'];
     $maxdate = $options['maxDate'];
     $buttonImage = $options['buttonImage'];
     $builder->setAttribute('changemonth', $changemonth);
     $builder->setAttribute('changeyear', $changeyear);
     $builder->setAttribute('mindate', $mindate);
     $builder->setAttribute('maxdate', $maxdate);
     $builder->setAttribute('buttonImage', $buttonImage);
     parent::buildForm($builder, $options);
 }
Example #5
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']);
 }
Example #6
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']);
 }
Example #7
0
 /**
  * Adds a CSRF field to the form when the CSRF protection is enabled.
  *
  * @param FormBuilder   $builder The form builder
  * @param array         $options The options
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     if (!$options['csrf_protection']) {
         return;
     }
     // use a low priority so higher priority listeners don't remove the field
     $builder->setAttribute('csrf_field_name', $options['csrf_field_name'])->setAttribute('csrf_provider', $options['csrf_provider'])->setAttribute('csrf_intention', $options['intention'])->setAttribute('csrf_factory', $builder->getFormFactory())->addEventSubscriber(new CsrfValidationListener($options['csrf_field_name'], $options['csrf_provider'], $options['intention']));
 }
Example #8
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']);
 }
Example #9
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());
         }
     }
 }
Example #10
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     if ($options['allow_add'] && $options['prototype']) {
         $prototype = $builder->create('$$' . $options['prototype_name'] . '$$', $options['type'], $options['options']);
         $builder->setAttribute('prototype', $prototype->getForm());
     }
     $listener = new ResizeFormListener($builder->getFormFactory(), $options['type'], $options['options'], $options['allow_add'], $options['allow_delete']);
     $builder->addEventSubscriber($listener)->setAttribute('allow_add', $options['allow_add'])->setAttribute('allow_delete', $options['allow_delete']);
 }
 /**
  * Adds a CSRF field to the form when the CSRF protection is enabled.
  *
  * @param FormBuilder $builder The form builder
  * @param array       $options The options
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     if (!$options['csrf_protection']) {
         return;
     }
     $listener = new EnsureCsrfFieldListener($builder->getFormFactory(), $options['csrf_field_name'], $options['intention'], $options['csrf_provider']);
     // use a low priority so higher priority listeners don't remove the field
     $builder->setAttribute('csrf_field_name', $options['csrf_field_name'])->addEventListener(FormEvents::PRE_SET_DATA, array($listener, 'ensureCsrfField'), -10)->addEventListener(FormEvents::PRE_BIND, array($listener, 'ensureCsrfField'), -10);
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     $type = $options['date_type'];
     //        unset($options['date_type']);
     $opt = $this->defDateOption();
     $opt['format'] = $options['format'];
     $builder->add('start', $type, $opt)->add('end', $type, $opt);
     $builder->setAttribute('widget', $options['widget']);
 }
Example #13
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());
            }
        }

    }
 private function getBuilder($name = 'name', $propertyPath = null, $dataClass = null)
 {
     $builder = new FormBuilder($name, $dataClass, $this->dispatcher, $this->factory);
     $builder->setPropertyPath(new PropertyPath($propertyPath ?: $name));
     $builder->setAttribute('error_mapping', array());
     $builder->setErrorBubbling(false);
     $builder->setMapped(true);
     return $builder;
 }
 public function buildForm(FormBuilder $builder, array $options)
 {
     if (empty($options['validation_groups'])) {
         $options['validation_groups'] = null;
     } else {
         $options['validation_groups'] = is_callable($options['validation_groups']) ? $options['validation_groups'] : (array) $options['validation_groups'];
     }
     $builder->setAttribute('validation_groups', $options['validation_groups'])->setAttribute('validation_constraint', $options['validation_constraint'])->setAttribute('cascade_validation', $options['cascade_validation'])->addValidator(new DelegatingValidator($this->validator));
 }
Example #16
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']);
 }
    public function buildForm(FormBuilder $builder, array $options)
    {
        $options['validation_groups'] = empty($options['validation_groups'])
            ? null
            : (array)$options['validation_groups'];

        $builder
            ->setAttribute('validation_groups', $options['validation_groups'])
            ->setAttribute('validation_constraint', $options['validation_constraint'])
            ->addValidator(new DelegatingValidator($this->validator));
    }
Example #18
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']);
 }
Example #19
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     if ($options['allow_add'] && $options['prototype']) {
         $prototype = $builder->create($options['prototype_name'], $options['type'], array_replace(array('label' => $options['prototype_name'] . 'label__'), $options['options']));
         $builder->setAttribute('prototype', $prototype->getForm());
     }
     $resizeListener = new ResizeFormListener($builder->getFormFactory(), $options['type'], $options['options'], $options['allow_add'], $options['allow_delete']);
     $builder->addEventSubscriber($resizeListener)->setAttribute('allow_add', $options['allow_add'])->setAttribute('allow_delete', $options['allow_delete']);
     // Enable support for adders/removers unless "by_reference" is disabled
     // (explicit calling of the setter is desired)
     if ($options['by_reference']) {
         $builder->addEventSubscriber(new MergeCollectionListener($options['allow_add'], $options['allow_delete'], MergeCollectionListener::MERGE_INTO_PARENT, $options['add_method'], $options['remove_method']));
     }
 }
Example #20
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']);
 }
 /**
  * {@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]);
         }
     }
 }
Example #22
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']);
 }
 public function buildForm(FormBuilder $builder, array $options)
 {
     $builder->setAttribute('widget_controls', $options['widget_controls']);
     if (!is_array($options['widget_addon'])) {
         throw new CreationException("The 'widget_addon' option must be an array");
     } else {
         $defaults = $this->getDefaultOptions($options);
         $options['widget_addon'] = array_merge($defaults['widget_addon'], $options['widget_addon']);
     }
     $builder->setAttribute('widget_addon', $options['widget_addon']);
     $builder->setAttribute('widget_prefix', $options['widget_prefix']);
     $builder->setAttribute('widget_suffix', $options['widget_suffix']);
     $builder->setAttribute('widget_type', $options['widget_type']);
     $builder->setAttribute('widget_remove_btn', $options['widget_remove_btn']);
 }
Example #24
0
 public function buildForm(FormBuilder $builder, array $options)
 {
     $builder->setAttribute('foo', 'x');
     $builder->setAttribute('data_option', $options['data']);
 }
 public function buildForm(FormBuilder $builder, array $options)
 {
     $builder->setAttribute('bar', 'x');
 }
Example #26
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     $builder->setAttribute('configs', $options['configs']);
 }
 public function buildForm(FormBuilder $builder, array $options)
 {
     $builder->setAttribute('render_fieldset', false)->setAttribute('show_legend', false)->add('search', 'text', array('label_render' => false, 'widget_controls' => false, 'attr' => array('placeholder' => "search", 'class' => "input-medium search-query")));
 }
Example #28
0
 public function buildForm(FormBuilder $builder, array $options)
 {
     $builder->setAttribute('always_empty', $options['always_empty']);
 }
Example #29
0
 public function buildForm(FormBuilder $builder, array $options)
 {
     $builder->setAttribute('virtual', $options['virtual'])->setDataMapper(new PropertyPathMapper($options['data_class']));
 }
Example #30
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilder $builder, array $options)
 {
     $options = $this->getDefaultOptions($options);
     $builder->setAttribute('years', $options['years'])->setAttribute('culture', $options['culture'])->setAttribute('configs', $options['configs']);
 }