Example #1
0
 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $optionsFilter = function (Options $options, $value) {
         $value['block_name'] = 'entry';
         return $value;
     };
     $resolver->setDefaults(array('allow_add' => false, 'allow_delete' => false, 'prototype' => true, 'prototype_name' => '__name__', 'type' => 'text', 'options' => array()));
     $resolver->setFilters(array('options' => $optionsFilter));
 }
 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     // BC clause
     $constraints = function (Options $options) {
         return $options['validation_constraint'];
     };
     // Make sure that validation groups end up as null, closure or array
     $validationGroupsFilter = function (Options $options, $groups) {
         if (empty($groups)) {
             return null;
         }
         if (is_callable($groups)) {
             return $groups;
         }
         return (array) $groups;
     };
     // Constraint should always be converted to an array
     $constraintsFilter = function (Options $options, $constraints) {
         return is_object($constraints) ? array($constraints) : (array) $constraints;
     };
     $resolver->setDefaults(array('error_mapping' => array(), 'validation_groups' => null, 'validation_constraint' => null, 'constraints' => $constraints, 'cascade_validation' => false, 'invalid_message' => 'This value is not valid.', 'extra_fields_message' => 'This form should not contain extra fields.', 'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.'));
     $resolver->setFilters(array('validation_groups' => $validationGroupsFilter, 'constraints' => $constraintsFilter));
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $choiceListCache =& $this->choiceListCache;
     $choiceList = function (Options $options) use(&$choiceListCache) {
         // Harden against NULL values (like in EntityType and ModelType)
         $choices = null !== $options['choices'] ? $options['choices'] : array();
         // Reuse existing choice lists in order to increase performance
         $hash = md5(json_encode(array($choices, $options['preferred_choices'])));
         if (!isset($choiceListCache[$hash])) {
             $choiceListCache[$hash] = new SimpleChoiceList($choices, $options['preferred_choices']);
         }
         return $choiceListCache[$hash];
     };
     $emptyData = function (Options $options) {
         if ($options['multiple'] || $options['expanded']) {
             return array();
         }
         return '';
     };
     $emptyValue = function (Options $options) {
         return $options['required'] ? null : '';
     };
     $emptyValueFilter = function (Options $options, $emptyValue) {
         if ($options['multiple'] || $options['expanded']) {
             // never use an empty value for these cases
             return null;
         } elseif (false === $emptyValue) {
             // an empty value should be added but the user decided otherwise
             return null;
         }
         // empty value has been set explicitly
         return $emptyValue;
     };
     $compound = function (Options $options) {
         return $options['expanded'];
     };
     $resolver->setDefaults(array('multiple' => false, 'expanded' => false, 'choice_list' => $choiceList, 'choices' => array(), 'preferred_choices' => array(), 'empty_data' => $emptyData, 'empty_value' => $emptyValue, 'error_bubbling' => false, 'compound' => $compound));
     $resolver->setFilters(array('empty_value' => $emptyValueFilter));
     $resolver->setAllowedTypes(array('choice_list' => array('null', 'Symfony\\Component\\Form\\Extension\\Core\\ChoiceList\\ChoiceListInterface')));
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $compound = function (Options $options) {
         return $options['widget'] !== 'single_text';
     };
     $emptyValue = $emptyValueDefault = function (Options $options) {
         return $options['required'] ? null : '';
     };
     $emptyValueFilter = function (Options $options, $emptyValue) use($emptyValueDefault) {
         if (is_array($emptyValue)) {
             $default = $emptyValueDefault($options);
             return array_merge(array('hour' => $default, 'minute' => $default, 'second' => $default), $emptyValue);
         }
         return array('hour' => $emptyValue, 'minute' => $emptyValue, 'second' => $emptyValue);
     };
     // BC until Symfony 2.3
     $modelTimezone = function (Options $options) {
         return $options['data_timezone'];
     };
     // BC until Symfony 2.3
     $viewTimezone = function (Options $options) {
         return $options['user_timezone'];
     };
     $resolver->setDefaults(array('hours' => range(0, 23), 'minutes' => range(0, 59), 'seconds' => range(0, 59), 'widget' => 'choice', 'input' => 'datetime', 'with_seconds' => false, 'model_timezone' => $modelTimezone, 'view_timezone' => $viewTimezone, 'data_timezone' => null, 'user_timezone' => null, 'empty_value' => $emptyValue, 'by_reference' => false, 'error_bubbling' => false, 'data_class' => null, 'compound' => $compound));
     $resolver->setFilters(array('empty_value' => $emptyValueFilter));
     $resolver->setAllowedValues(array('input' => array('datetime', 'string', 'timestamp', 'array'), 'widget' => array('single_text', 'text', 'choice')));
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $compound = function (Options $options) {
         return $options['widget'] !== 'single_text';
     };
     $emptyValue = $emptyValueDefault = function (Options $options) {
         return $options['required'] ? null : '';
     };
     $emptyValueFilter = function (Options $options, $emptyValue) use($emptyValueDefault) {
         if (is_array($emptyValue)) {
             $default = $emptyValueDefault($options);
             return array_merge(array('year' => $default, 'month' => $default, 'day' => $default), $emptyValue);
         }
         return array('year' => $emptyValue, 'month' => $emptyValue, 'day' => $emptyValue);
     };
     $resolver->setDefaults(array('years' => range(date('Y') - 5, date('Y') + 5), 'months' => range(1, 12), 'days' => range(1, 31), 'widget' => 'choice', 'input' => 'datetime', 'format' => self::DEFAULT_FORMAT, 'data_timezone' => null, 'user_timezone' => null, 'empty_value' => $emptyValue, 'by_reference' => false, 'error_bubbling' => false, 'data_class' => null, 'compound' => $compound));
     $resolver->setFilters(array('empty_value' => $emptyValueFilter));
     $resolver->setAllowedValues(array('input' => array('datetime', 'string', 'timestamp', 'array'), 'widget' => array('single_text', 'text', 'choice')));
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $compound = function (Options $options) {
         return $options['widget'] !== 'single_text';
     };
     $emptyValueFilter = function (Options $options, $emptyValue) {
         if (is_array($emptyValue)) {
             return array_merge(array('hour' => null, 'minute' => null, 'second' => null), $emptyValue);
         }
         return array('hour' => $emptyValue, 'minute' => $emptyValue, 'second' => $emptyValue);
     };
     $resolver->setDefaults(array('hours' => range(0, 23), 'minutes' => range(0, 59), 'seconds' => range(0, 59), 'widget' => 'choice', 'input' => 'datetime', 'with_seconds' => false, 'data_timezone' => null, 'user_timezone' => null, 'empty_value' => null, 'by_reference' => false, 'error_bubbling' => false, 'data_class' => null, 'compound' => $compound));
     $resolver->setFilters(array('empty_value' => $emptyValueFilter));
     $resolver->setAllowedValues(array('input' => array('datetime', 'string', 'timestamp', 'array'), 'widget' => array('single_text', 'text', 'choice')));
 }
Example #7
0
 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $choiceList = function (Options $options) {
         return new SimpleChoiceList(null !== $options['choices'] ? $options['choices'] : array(), $options['preferred_choices']);
     };
     $emptyData = function (Options $options) {
         if ($options['multiple'] || $options['expanded']) {
             return array();
         }
         return '';
     };
     $emptyValue = function (Options $options) {
         return $options['required'] ? null : '';
     };
     $emptyValueFilter = function (Options $options, $emptyValue) {
         if ($options['multiple'] || $options['expanded']) {
             // never use an empty value for these cases
             return null;
         } elseif (false === $emptyValue) {
             // an empty value should be added but the user decided otherwise
             return null;
         }
         // empty value has been set explicitly
         return $emptyValue;
     };
     $compound = function (Options $options) {
         return $options['expanded'];
     };
     $resolver->setDefaults(array('multiple' => false, 'expanded' => false, 'choice_list' => $choiceList, 'choices' => array(), 'preferred_choices' => array(), 'empty_data' => $emptyData, 'empty_value' => $emptyValue, 'error_bubbling' => false, 'compound' => $compound));
     $resolver->setFilters(array('empty_value' => $emptyValueFilter));
     $resolver->setAllowedTypes(array('choice_list' => array('null', 'Symfony\\Component\\Form\\Extension\\Core\\ChoiceList\\ChoiceListInterface')));
 }