/** * Reference purchase summary * * @Route() * @Method({"GET", "POST"}) * @Template() * * @param Request $request * @return \Symfony\Component\HttpFoundation\Response */ public function indexAction(Request $request) { $previouslyPostedData = null; // if we are not posting new data, and a request for $this->formType is stored in the session, prepopulate the form with the stored request $storedRequest = unserialize($request->getSession()->get($this->formType->getName())); if ($request->isMethod('GET') && $storedRequest instanceof Request) { $previouslyPostedData = $this->createForm($this->formType)->handleRequest($storedRequest)->getData(); } $form = $this->createForm($this->formType, $previouslyPostedData); if ($request->isMethod('POST')) { $form->submit($request); if ($form->isValid()) { // Persist the case to IRIS /** @var ReferencingCase $case */ $case = $form->getData()['case']; $this->irisEntityManager->persist($case); /** @var ReferencingApplication $application */ foreach ($case->getApplications() as $application) { // Always default $application->setSignaturePreference(SignaturePreference::SCAN_DECLARATION); $this->irisEntityManager->persist($application, array('caseId' => $case->getCaseId())); // Persist each guarantor of the application if (null !== $application->getGuarantors()) { foreach ($application->getGuarantors() as $guarantor) { $this->irisEntityManager->persist($guarantor, array('applicationId' => $application->getApplicationId())); } } } $request->getSession()->set('submitted-case', serialize($case)); // Send the user to the success page return $this->redirect($this->generateUrl('barbon_hostedapi_agent_reference_newreference_tenancyagreement_index'), 301); } } return array('form' => $form->createView()); }
/** * @param FormTypeInterface $type * @param OptionsResolver $optionsResolver * * @internal */ public static function configureOptions(FormTypeInterface $type, OptionsResolver $optionsResolver) { if (!method_exists('Symfony\\Component\\Form\\AbstractType', 'getBlockPrefix')) { $type->setDefaultOptions($optionsResolver); } else { $type->configureOptions($optionsResolver); } }
/** * @inheritdoc */ private function resolveType(FormTypeInterface $type) { $parentType = $type->getParent(); if ($parentType instanceof FormTypeInterface) { $parentType = $this->resolveType($parentType); } elseif (null !== $parentType) { $parentType = $this->registry->getType($parentType); } return $this->resolvedTypeFactory->createResolvedType($type, array(), $parentType); }
/** * {@inheritdoc} */ public function resolveType(FormTypeInterface $type) { $typeExtensions = array(); foreach ($this->extensions as $extension) { /* @var FormExtensionInterface $extension */ $typeExtensions = array_merge($typeExtensions, $extension->getTypeExtensions($type->getName())); } $parent = $type->getParent() ? $this->getType($type->getParent()) : null; return new ResolvedFormType($type, $typeExtensions, $parent); }
/** * Returns the configured options resolver used for this type. * * @return \Symfony\Component\OptionsResolver\OptionsResolverInterface The options resolver. */ public function getOptionsResolver() { if (null === $this->optionsResolver) { if (null !== $this->parent) { $this->optionsResolver = clone $this->parent->getOptionsResolver(); } else { $this->optionsResolver = new OptionsResolver(); } $this->innerType->setDefaultOptions($this->optionsResolver); $reflector = new \ReflectionMethod($this->innerType, 'setDefaultOptions'); $isOldOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\\Component\\Form\\AbstractType'; $reflector = new \ReflectionMethod($this->innerType, 'configureOptions'); $isNewOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\\Component\\Form\\AbstractType'; if ($isOldOverwritten && !$isNewOverwritten) { trigger_error('The FormTypeInterface::setDefaultOptions() method is deprecated since version 2.7 and will be removed in 3.0. Use configureOptions() instead. This method will be added to the FormTypeInterface with Symfony 3.0.', E_USER_DEPRECATED); } foreach ($this->typeExtensions as $extension) { $extension->setDefaultOptions($this->optionsResolver); $reflector = new \ReflectionMethod($extension, 'setDefaultOptions'); $isOldOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\\Component\\Form\\AbstractTypeExtension'; $reflector = new \ReflectionMethod($extension, 'configureOptions'); $isNewOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\\Component\\Form\\AbstractTypeExtension'; if ($isOldOverwritten && !$isNewOverwritten) { trigger_error('The FormTypeExtensionInterface::setDefaultOptions() method is deprecated since version 2.7 and will be removed in 3.0. Use configureOptions() instead. This method will be added to the FormTypeExtensionInterface with Symfony 3.0.', E_USER_DEPRECATED); } } } return $this->optionsResolver; }
/** * Triggered on every request. * * @param GetResponseEvent $event * * @return void */ public function onKernelRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { // don't do anything if it's not the master request return; } $request = $event->getRequest(); // if the request contains a key equal to the name of the form in this class... $acceptableContentTypes = array_map('strtolower', $request->getAcceptableContentTypes()); if ($request->request->has($this->formType->getName()) && in_array('text/html', $acceptableContentTypes) && !$request->isXmlHttpRequest()) { // store the request so we can retrieve the posted form data later, if necessary $request->getSession()->set($this->formType->getName(), serialize($request)); // whilst we are here, store the target URL of the form, in case we are redirected to login page // $request->getSession()->set('_security.asn_secured.target_path', $request->getUri()); } }
public function testGetBlockPrefix() { $this->type->expects($this->once()) ->method('getBlockPrefix') ->willReturn('my_prefix'); $resolvedType = new ResolvedFormType($this->type); $this->assertSame('my_prefix', $resolvedType->getBlockPrefix()); }
/** * Returns the configured options resolver used for this type. * * @return \Symfony\Component\OptionsResolver\OptionsResolverInterface The options resolver. */ public function getOptionsResolver() { if (null === $this->optionsResolver) { if (null !== $this->parent) { $this->optionsResolver = clone $this->parent->getOptionsResolver(); } else { $this->optionsResolver = new OptionsResolver(); } $this->innerType->setDefaultOptions($this->optionsResolver); foreach ($this->typeExtensions as $extension) { $extension->setDefaultOptions($this->optionsResolver); } } return $this->optionsResolver; }
/** * Wraps a type into a ResolvedFormTypeInterface implementation and connects * it with its parent type. * * @param FormTypeInterface $type The type to resolve. * * @return ResolvedFormTypeInterface The resolved type. */ private function resolveAndAddType(FormTypeInterface $type) { $parentType = $type->getParent(); if ($parentType instanceof FormTypeInterface) { $this->resolveAndAddType($parentType); $parentType = $parentType->getName(); } $typeExtensions = array(); foreach ($this->extensions as $extension) { $typeExtensions = array_merge($typeExtensions, $extension->getTypeExtensions($type->getName())); } $this->types[$type->getName()] = $this->resolvedTypeFactory->createResolvedType($type, $typeExtensions, $parentType ? $this->getType($parentType) : null); }
private function validateFormTypeName(FormTypeInterface $type) { if (!preg_match('/^[a-z0-9_]*$/i', $type->getName())) { throw new FormException(sprintf('The "%s" form type name ("%s") is not valid. Names must only contain letters, numbers, and "_".', get_class($type), $type->getName())); } }
/** * Wraps a type into a ResolvedFormTypeInterface implementation and connects * it with its parent type. * * @param FormTypeInterface $type The type to resolve. * * @return ResolvedFormTypeInterface The resolved type. */ private function resolveAndAddType(FormTypeInterface $type) { $parentType = $type->getParent(); if ($parentType instanceof FormTypeInterface) { $this->resolveAndAddType($parentType); $parentType = $parentType->getName(); } $typeExtensions = array(); foreach ($this->extensions as $extension) { /* @var FormExtensionInterface $extension */ $typeExtensions = array_merge($typeExtensions, $extension->getTypeExtensions($type->getName())); } set_error_handler(array('Symfony\\Component\\Form\\Test\\DeprecationErrorHandler', 'handleBC')); $this->addType($this->resolvedTypeFactory->createResolvedType($type, $typeExtensions, $parentType ? $this->getType($parentType) : null)); restore_error_handler(); }
/** * Wraps a type into a ResolvedFormTypeInterface implementation and connects * it with its parent type. * * @param FormTypeInterface $type The type to resolve. * * @return ResolvedFormTypeInterface The resolved type. */ private function resolveAndAddType(FormTypeInterface $type) { $typeExtensions = array(); $parentType = $type->getParent(); $fqcn = get_class($type); $name = $type->getName(); $hasCustomName = $name !== $fqcn; if ($parentType instanceof FormTypeInterface) { @trigger_error('Returning a FormTypeInterface from FormTypeInterface::getParent() is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); $this->resolveAndAddType($parentType); $parentType = $parentType->getName(); } if ($hasCustomName) { foreach ($this->extensions as $extension) { $typeExtensions = array_merge($typeExtensions, $extension->getTypeExtensions($name)); } if ($typeExtensions) { @trigger_error('Returning a type name from FormTypeExtensionInterface::getExtendedType() is deprecated since version 2.8 and will be removed in 3.0. Return the fully-qualified type class name instead.', E_USER_DEPRECATED); } } foreach ($this->extensions as $extension) { $typeExtensions = array_merge($typeExtensions, $extension->getTypeExtensions($fqcn)); } $resolvedType = $this->resolvedTypeFactory->createResolvedType($type, $typeExtensions, $parentType ? $this->getType($parentType) : null); $this->types[$fqcn] = $resolvedType; if ($hasCustomName) { // Enable access by the explicit type name until Symfony 3.0 $this->types[$name] = $resolvedType; $this->legacyNames[$name] = true; } }
/** * Wraps a type into a ResolvedFormTypeInterface implementation and connects * it with its parent type. * * @param FormTypeInterface $type The type to resolve. * * @return ResolvedFormTypeInterface The resolved type. */ private function resolveType(FormTypeInterface $type) { $typeExtensions = array(); $parentType = $type->getParent(); $fqcn = get_class($type); foreach ($this->extensions as $extension) { $typeExtensions = array_merge($typeExtensions, $extension->getTypeExtensions($fqcn)); } return $this->resolvedTypeFactory->createResolvedType($type, $typeExtensions, $parentType ? $this->getType($parentType) : null); }
/** * {@inheritdoc} */ public function getParent() { return $this->parentType->getName(); }
public function __construct(FormTypeInterface $type, $code = 0, $previous = null) { parent::__construct(sprintf('Circular reference detected in the "%s" type (defined in class "%s").', $type->getName(), get_class($type)), $code, $previous); }
/** * @param string|\Symfony\Component\Form\FormTypeInterface $formType * * @return ConfigCache */ protected function configCacheFor($formType) { $filename = $formType instanceof FormTypeInterface ? $formType->getName() : $formType; return new ConfigCache($this->cacheDirectory . '/' . $filename, $this->debug); }
public function addType(FormTypeInterface $type) { $this->types[$type->getName()] = $type; }
/** * Loads the extensions for a given type. * * @param FormTypeInterface $type The type */ private function loadTypeExtensions(FormTypeInterface $type) { $typeExtensions = array(); foreach ($this->extensions as $extension) { $typeExtensions = array_merge($typeExtensions, $extension->getTypeExtensions($type->getName())); } $type->setExtensions($typeExtensions); }
/** * Adds a type. * * @param FormTypeInterface $type The type * * @deprecated Deprecated since version 2.1, to be removed in 2.3. Use * form extensions or type registration in the Dependency * Injection Container instead. */ public function addType(FormTypeInterface $type) { $parentType = $type->getParent(); $this->registry->addType($this->resolvedTypeFactory->createResolvedType($type, array(), $parentType ? $this->registry->getType($parentType) : null)); }
/** * Wraps a type into a ResolvedFormTypeInterface implementation and connects * it with its parent type. * * @param FormTypeInterface $type The type to resolve. * * @return ResolvedFormTypeInterface The resolved type. */ private function resolveType(FormTypeInterface $type) { $parentType = $type->getParent(); if ($parentType instanceof FormTypeInterface) { $parentType = $this->resolveType($parentType); } elseif (null !== $parentType) { $parentType = $this->registry->getType($parentType); } return $this->resolvedTypeFactory->createResolvedType( $type, // Type extensions are not supported for unregistered type instances, // i.e. type instances that are passed to the FormFactory directly, // nor for their parents, if getParent() also returns a type instance. array(), $parentType ); }