示例#1
0
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     parent::configureOptions($resolver);
     // Derive "data_class" option from passed "data" object
     $dataClass = function (Options $options) {
         return isset($options['data']) && is_object($options['data']) ? get_class($options['data']) : null;
     };
     // Derive "empty_data" closure from "data_class" option
     $emptyData = function (Options $options) {
         $class = $options['data_class'];
         if (null !== $class) {
             return function (FormInterface $form) use($class) {
                 return $form->isEmpty() && !$form->isRequired() ? null : new $class();
             };
         }
         return function (FormInterface $form) {
             return $form->getConfig()->getCompound() ? array() : '';
         };
     };
     // For any form that is not represented by a single HTML control,
     // errors should bubble up by default
     $errorBubbling = function (Options $options) {
         return $options['compound'];
     };
     // If data is given, the form is locked to that data
     // (independent of its value)
     $resolver->setDefined(array('data'));
     $resolver->setDefaults(array('data_class' => $dataClass, 'empty_data' => $emptyData, 'trim' => true, 'required' => true, 'property_path' => null, 'mapped' => true, 'by_reference' => true, 'error_bubbling' => $errorBubbling, 'label_attr' => array(), 'inherit_data' => false, 'compound' => true, 'method' => 'POST', 'action' => '', 'attr' => array(), 'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.'));
     $resolver->setAllowedTypes('label_attr', 'array');
 }
示例#2
0
文件: FormType.php 项目: Dren-x/mobit
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     parent::configureOptions($resolver);
     // Derive "data_class" option from passed "data" object
     $dataClass = function (Options $options) {
         return isset($options['data']) && is_object($options['data']) ? get_class($options['data']) : null;
     };
     // Derive "empty_data" closure from "data_class" option
     $emptyData = function (Options $options) {
         $class = $options['data_class'];
         if (null !== $class) {
             return function (FormInterface $form) use($class) {
                 return $form->isEmpty() && !$form->isRequired() ? null : new $class();
             };
         }
         return function (FormInterface $form) {
             return $form->getConfig()->getCompound() ? array() : '';
         };
     };
     // For any form that is not represented by a single HTML control,
     // errors should bubble up by default
     $errorBubbling = function (Options $options) {
         return $options['compound'];
     };
     // BC with old "virtual" option
     $inheritData = function (Options $options) {
         if (null !== $options['virtual']) {
             @trigger_error('The form option "virtual" is deprecated since version 2.3 and will be removed in 3.0. Use "inherit_data" instead.', E_USER_DEPRECATED);
             return $options['virtual'];
         }
         return false;
     };
     // If data is given, the form is locked to that data
     // (independent of its value)
     $resolver->setDefined(array('data'));
     // BC clause for the "max_length" and "pattern" option
     // Add these values to the "attr" option instead
     $defaultAttr = function (Options $options) {
         $attributes = array();
         if (null !== $options['max_length']) {
             $attributes['maxlength'] = $options['max_length'];
         }
         if (null !== $options['pattern']) {
             $attributes['pattern'] = $options['pattern'];
         }
         return $attributes;
     };
     $resolver->setDefaults(array('data_class' => $dataClass, 'empty_data' => $emptyData, 'trim' => true, 'required' => true, 'read_only' => false, 'max_length' => null, 'pattern' => null, 'property_path' => null, 'mapped' => true, 'by_reference' => true, 'error_bubbling' => $errorBubbling, 'label_attr' => array(), 'virtual' => null, 'inherit_data' => $inheritData, 'compound' => true, 'method' => 'POST', 'action' => '', 'attr' => $defaultAttr, 'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.'));
     $resolver->setAllowedTypes('label_attr', 'array');
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(array('auto_initialize' => false));
 }