* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; use Symfony\Component\Form\Extension\Core\EventListener\TrimListener; use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper; use Symfony\Component\Form\Exception\LogicException; use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\PropertyAccess\PropertyAccessorInterface; class FormType extends BaseType { private $propertyAccessor; public function __construct(PropertyAccessorInterface $propertyAccessor = null) { $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor(); } /** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { parent::buildForm($builder, $options); $isDataOptionSet = array_key_exists('data', $options); $builder ->setRequired($options['required']) ->setErrorBubbling($options['error_bubbling']) ->setEmptyData($options['empty_data']) ->setPropertyPath($options['property_path']) ->setMapped($options['mapped']) ->setByReference($options['by_reference']) ->setInheritData($options['inherit_data']) ->setCompound($options['compound']) ->setData($isDataOptionSet ? $options['data'] : null) ->setDataLocked($isDataOptionSet) ->setDataMapper($options['compound'] ? new PropertyPathMapper($this->propertyAccessor) : null) ->setMethod($options['method']) ->setAction($options['action']); if ($options['trim']) { $builder->addEventSubscriber(new TrimListener()); } } /** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { parent::buildView($view, $form, $options); $name = $form->getName(); if ($view->parent) { if ('' === $name) { throw new LogicException('Form node with empty name can be used only as root form node.'); } // Complex fields are read-only if they themselves or their parents are. if (!isset($view->vars['attr']['readonly']) && isset($view->parent->vars['attr']['readonly']) && false !== $view->parent->vars['attr']['readonly']) { $view->vars['attr']['readonly'] = true; } } $formConfig = $form->getConfig(); $view->vars = array_replace($view->vars, array( 'errors' => $form->getErrors(), 'valid' => $form->isSubmitted() ? $form->isValid() : true, 'value' => $form->getViewData(), 'data' => $form->getNormData(), 'required' => $form->isRequired(), 'size' => null, 'label_attr' => $options['label_attr'], 'compound' => $formConfig->getCompound(), 'method' => $formConfig->getMethod(), 'action' => $formConfig->getAction(), 'submitted' => $form->isSubmitted(), )); } /** * {@inheritdoc} */ public function finishView(FormView $view, FormInterface $form, array $options) { $multipart = false; foreach ($view->children as $child) { if ($child->vars['multipart']) { $multipart = true; break; } } $view->vars['multipart'] = $multipart; } /** * {@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() : ''; }; }; // Wrap "post_max_size_message" in a closure to translate it lazily $uploadMaxSizeMessage = function (Options $options) { return function () use ($options) { return $options['post_max_size_message']; }; }; // 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', // According to RFC 2396 (http://www.ietf.org/rfc/rfc2396.txt) // section 4.2., empty URIs are considered same-document references 'action' => '', 'attr' => array(), 'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.', 'upload_max_size_message' => $uploadMaxSizeMessage, // internal )); $resolver->setAllowedTypes('label_attr', 'array'); $resolver->setAllowedTypes('upload_max_size_message', array('callable')); } /** * {@inheritdoc} */ public function getParent() { } /** * {@inheritdoc} */ public function getBlockPrefix() { return 'form'; } } __halt_compiler();----SIGNATURE:----ESfFJbgpA5WiHYTyoz1nWOrSPNgyQS8610baCYCp60oHP7gr/9Tv8l2Tj8CG0JI4JaWDq/39zOshTq6PKPpiXrIMDGPWMlhwhdO2/gyLnnn5fXA3liHAkRe8t8lOmm+gZQzfbeoUHSaoibDem71PIDS3mUciH1GUYkIXeycnpx8nP3RVrsPK5CW0cKa74sYizWexAq2v79e3Bx6taBURIlyFofjAuDf6+WlX/HjUBWUes+yr34OBiidTNjmemM0kIh0/wVJ+g7Ij/2n1uLE/84bYPOV7VCrlQpYv8768J1BjPm1JfxtH/4Go/GcXFoMhKCRc3xV+zX08IX9QhCZxEWGUQk6TZIPXg5DLAB4j8n9J+0TCjtr1LLVs7gMzqlWVH/JM2glXL6ek2HxVyd9AWQIT+wWDNQfZ0/1RoGdFVfAq3kqyQ7oimb9pVmEvhkIWYjliwi2nEtjjcupsde62L3YP7AAyYQrNKV2UuLlSIWkcPu+NxIaYRk8MR0unxfnAMDMT/xDBVWDP2Q5f8oI/x8uWAxAs1qsq+xya9jv4iww6iMB2HMwBbpaerp2+5VMvkmQA8TXVwbdeBvhNgtL7IBJEBUti/i5n4yrdiZh41p4P/8c4XruKK52O7T1NhEt2F/KOpGyDTaOj20FnPN1F4qatOsYJmKnD5H7drO9qGfY=----ATTACHMENT:----NDYxMTIyOTExNzYwNDE4NCA4NzA0NDE3NTQ3OTk3MjA5IDI5NDEzMjU1ODYyNDkxMzk=