本文整理汇总了PHP中Symfony\Component\Form\FormInterface::get方法的典型用法代码示例。如果您正苦于以下问题:PHP FormInterface::get方法的具体用法?PHP FormInterface::get怎么用?PHP FormInterface::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormInterface
的用法示例。
在下文中一共展示了FormInterface::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* @param FormInterface $form
* @param Request $request
* @return AccountUser|bool
*/
public function process(FormInterface $form, Request $request)
{
if ($request->isMethod('POST')) {
$form->submit($request);
if ($form->isValid()) {
$email = $form->get('email')->getData();
/** @var AccountUser $user */
$user = $this->userManager->findUserByUsernameOrEmail($email);
if ($this->validateUser($form, $email, $user)) {
if (null === $user->getConfirmationToken()) {
$user->setConfirmationToken($user->generateToken());
}
try {
$this->userManager->sendResetPasswordEmail($user);
$user->setPasswordRequestedAt(new \DateTime('now', new \DateTimeZone('UTC')));
$this->userManager->updateUser($user);
return $user;
} catch (\Exception $e) {
$this->addFormError($form, 'oro.email.handler.unable_to_send_email');
}
}
}
}
return false;
}
示例2: chooseGroups
/**
* {@inheritdoc}
*/
public function chooseGroups(FormInterface $form)
{
$phoneData = $form->get('phone')->getData();
$mobileData = $form->get('mobile')->getData();
// All other fields are validated through the Default validation group
$validation_groups = array('Default');
// If both or neither phone and mobile fields are given,
// validate both fields
if (empty($phoneData) && empty($mobileData)) {
$validation_groups[] = 'phone';
$validation_groups[] = 'mobile';
} else {
// If only phone field alone is given, validate, but
// not mobile. Only 1 is required.
if (!empty($phoneData)) {
$validation_groups[] = 'phone';
}
// If only mobile field alone is given, validate, but
// not phone. Only 1 is required.
if (!empty($mobileData)) {
$validation_groups[] = 'mobile';
}
}
return $validation_groups;
}
示例3: chooseGroups
/**
* {@inheritdoc}
*/
public function chooseGroups(FormInterface $form)
{
if (!$form->get('flat')->getData() && !$form->get('houseName')->getData() && !$form->get('houseNumber')->getData()) {
return array('Default', 'propertyIdentifier', 'postcode');
}
return array('Default', 'postcode');
}
示例4: process
/**
* Prepare & process form
*
* @author Jeremie Samson <jeremie@ylly.fr>
*
* @return bool
*/
public function process()
{
if ($this->request->isMethod('POST')) {
$this->form->handleRequest($this->request);
if ($this->form->isValid()) {
/** @var ModelUserRole $model */
$model = $this->form->getData();
if (!$model->getUser() || !$model->getRole()) {
$this->form->addError(new FormError('Missing parameter(s)'));
}
/** @var User $user */
$user = $this->em->getRepository('UserBundle:User')->find($model->getUser());
/** @var Post $role */
$role = $this->em->getRepository('FaucondorBundle:Post')->find($model->getRole());
if (!$user) {
$this->form->get('user')->addError(new FormError('User with id ' . $model->getUser() . ' not found '));
}
if (!$role) {
$this->form->get('role')->addError(new FormError('Role with id ' . $model->getRole() . ' not found '));
}
$this->onSuccess($user, $role);
return true;
}
}
return false;
}
示例5: process
/**
* Process form
*
* @param Task $entity
*
* @return bool True on successful processing, false otherwise
*/
public function process(Task $entity)
{
$action = $this->entityRoutingHelper->getAction($this->request);
$targetEntityClass = $this->entityRoutingHelper->getEntityClassName($this->request);
$targetEntityId = $this->entityRoutingHelper->getEntityId($this->request);
if ($targetEntityClass && !$entity->getId() && $this->request->getMethod() === 'GET' && $action === 'assign' && is_a($targetEntityClass, 'Oro\\Bundle\\UserBundle\\Entity\\User', true)) {
$entity->setOwner($this->entityRoutingHelper->getEntity($targetEntityClass, $targetEntityId));
FormUtils::replaceField($this->form, 'owner', ['read_only' => true]);
}
$this->form->setData($entity);
if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
$this->form->submit($this->request);
if ($this->form->isValid()) {
// TODO: should be refactored after finishing BAP-8722
// Contexts handling should be moved to common for activities form handler
if ($this->form->has('contexts')) {
$contexts = $this->form->get('contexts')->getData();
$this->activityManager->setActivityTargets($entity, $contexts);
} elseif ($targetEntityClass && $action === 'activity') {
// if we don't have "contexts" form field
// we should save association between activity and target manually
$this->activityManager->addActivityTarget($entity, $this->entityRoutingHelper->getEntityReference($targetEntityClass, $targetEntityId));
}
$this->onSuccess($entity);
return true;
}
}
return false;
}
示例6: process
/**
* Process form
*
* @param AccountUser $accountUser
* @return bool True on successful processing, false otherwise
*/
public function process(AccountUser $accountUser)
{
if (in_array($this->request->getMethod(), ['POST', 'PUT'], true)) {
$this->form->submit($this->request);
if ($this->form->isValid()) {
if (!$accountUser->getId()) {
if ($this->form->get('passwordGenerate')->getData()) {
$generatedPassword = $this->userManager->generatePassword(10);
$accountUser->setPlainPassword($generatedPassword);
}
if ($this->form->get('sendEmail')->getData()) {
$this->userManager->sendWelcomeEmail($accountUser);
}
}
$token = $this->securityFacade->getToken();
if ($token instanceof OrganizationContextTokenInterface) {
$organization = $token->getOrganizationContext();
$accountUser->setOrganization($organization)->addOrganization($organization);
}
$this->userManager->updateUser($accountUser);
return true;
}
}
return false;
}
示例7: chooseGroups
/**
* {@inheritdoc}
*/
public function chooseGroups(FormInterface $form)
{
$dayPhoneData = $form->get('dayPhone')->getData();
$eveningPhoneData = $form->get('eveningPhone')->getData();
$emailData = $form->get('email')->getData();
// All other fields are validated through the Default validation group
$validation_groups = array('Default');
// todo: is there an apprpoach that does not require the sdk models?
/** @var ReferencingApplication $application */
$application = $form->getParent()->getData();
if ($application instanceof ReferencingApplication) {
// If Optimum product, require at least one contact detail must be given
if (19 == $application->getProductId()) {
if (empty($dayPhoneData) && empty($eveningPhoneData) && empty($emailData)) {
$validation_groups[] = 'dayphone';
$validation_groups[] = 'eveningphone';
$validation_groups[] = 'email';
}
}
// If no day phone, enforce evening
if (empty($dayPhoneData)) {
$validation_groups[] = 'eveningphone';
}
// If no evening phone, enforce day
if (empty($eveningPhoneData)) {
if ($k = array_search('eveningphone', $validation_groups)) {
unset($validation_groups[$k]);
}
$validation_groups[] = 'dayphone';
}
return $validation_groups;
}
return array('Default');
}
示例8: process
/**
* Prepare & process form
*
* @author Jeremie Samson <jeremie@ylly.fr>
*
* @return bool
*/
public function process()
{
if ($this->request->isMethod('POST')) {
$this->form->handleRequest($this->request);
if ($this->form->isValid()) {
/** @var ModelUser $user */
$user = $this->form->getData();
if (!$user->getFirstname() || !$user->getLastname() || !$user->getEmailGalaxy() || !$user->getSection()) {
$this->form->addError(new FormError('Missing parameter(s)'));
} else {
if (!filter_var($user->getEmail(), FILTER_VALIDATE_EMAIL) || !filter_var($user->getEmailGalaxy(), FILTER_VALIDATE_EMAIL)) {
$error = new FormError('email invalid');
if (!filter_var($user->getEmail(), FILTER_VALIDATE_EMAIL)) {
$this->form->get('email')->addError($error);
}
if (!filter_var($user->getEmailGalaxy(), FILTER_VALIDATE_EMAIL)) {
$this->form->get('emailGalaxy')->addError($error);
}
} else {
$section_id = $this->em->getRepository('FaucondorBundle:Section')->find($user->getSection());
$section_code = $this->em->getRepository('FaucondorBundle:Section')->findOneBy(array("code" => $user->getSection()));
if (!$section_id && !$section_code) {
$this->form->get('section')->addError(new FormError('Section with id ' . $user->getSection() . ' not found'));
} else {
/** @var Section $section */
$section = $section_id ? $section_id : $section_code;
$this->onSuccess($user, $section);
return true;
}
}
}
}
}
return false;
}
示例9: finishView
/**
* {@inheritdoc}
*/
public function finishView(FormView $view, FormInterface $form, array $options)
{
$view->vars['entityId'] = $form->get('entityId')->getData();
$view->vars['entityClass'] = $form->get('entityClass')->getData();
$routeParameters = isset($view->children['entities']->vars['configs']['route_parameters']) ? $view->children['entities']->vars['configs']['route_parameters'] : [];
$routeParameters['entityClass'] = $form->get('entityClass')->getData();
$view->children['entities']->vars['configs']['route_parameters'] = $routeParameters;
}
示例10: createEmptyData
/**
* {@inheritdoc}
*/
protected function createEmptyData(FormInterface $form)
{
$user = $form->get('user')->getData();
if (!$user instanceof UserInterface) {
$user = $this->user;
}
return $this->factory->create($this->options['project'], $user, $form->get('role')->getData());
}
示例11: handleContacts
/**
* @param Account $entity
*/
protected function handleContacts($entity)
{
if ($this->form->has('contacts')) {
$contacts = $this->form->get('contacts');
$this->appendContacts($entity, $contacts->get('added')->getData());
$this->removeContacts($entity, $contacts->get('removed')->getData());
}
}
示例12: buildView
/**
* Passe la config du champ à la vue
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
if ($form->get('content')->isDisabled()) {
$form->get('content')->addError(new FormError('calendar.error.all_calendars_selected'));
} elseif (count($this->choices) == 0) {
$form->get('content')->addError(new FormError('calendar.error.no_calendars_found'));
}
}
示例13: testErrorSubmit
/**
* @dataProvider getInvalidInputs
*/
public function testErrorSubmit($submitted, $expected, array $invalidFields = [])
{
$this->sut->submit($submitted);
$this->assertFalse($this->sut->isValid());
foreach ($invalidFields as $child) {
$this->assertFalse($this->sut->get($child)->isValid(), "{$child} isValid");
}
$this->assertEquals($expected, $this->sut->getData());
}
示例14: onSuccess
/**
* @param GridView $entity
*/
protected function onSuccess(GridView $entity)
{
$default = $this->form->get('is_default')->getData();
$this->setDefaultGridView($entity, $default);
$this->fixFilters($entity);
$om = $this->registry->getManagerForClass('OroDataGridBundle:GridView');
$om->persist($entity);
$om->flush();
}
示例15: onRegistrationCompleted
public function onRegistrationCompleted(FilterUserResponseEvent $event)
{
$user = $event->getUser();
$tenantName = $this->_form->get('tenantName')->getData();
$tenantSubdomain = $this->_form->get('tenantSubdomain')->getData();
$tenant = $this->registrationManager->createTenant($user, $tenantName, $tenantSubdomain);
// this referenced redirect response will be used
$this->redirectResponse->setTargetUrl($this->tenantAwareRouter->generateUrl($tenant));
unset($this->_form);
}