当前位置: 首页>>代码示例>>PHP>>正文


PHP FormInterface::has方法代码示例

本文整理汇总了PHP中Symfony\Component\Form\FormInterface::has方法的典型用法代码示例。如果您正苦于以下问题:PHP FormInterface::has方法的具体用法?PHP FormInterface::has怎么用?PHP FormInterface::has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Form\FormInterface的用法示例。


在下文中一共展示了FormInterface::has方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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;
 }
开发者ID:antrampa,项目名称:crm,代码行数:36,代码来源:TaskHandler.php

示例2: testFields

 public function testFields()
 {
     $this->assertCount(2, $this->form);
     $this->assertTrue($this->form->has('_operation'));
     $view = $this->form->createView();
     $this->assertCount(1, $view['_operation']);
     $this->assertArrayHasKey('confirm', $view['_operation']);
 }
开发者ID:issei-m,项目名称:confirmable-form,代码行数:8,代码来源:FormTypeOperationExtensionTest.php

示例3: 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());
     }
 }
开发者ID:dairdr,项目名称:crm,代码行数:11,代码来源:AccountHandler.php

示例4: validateFields

 protected function validateFields(FormInterface $form, $data)
 {
     if (!in_array($data->getType(), OneTimeContribution::getTypeChoices())) {
         $form->get('type')->addError(new FormError('Choose an option.'));
     } else {
         if ($data->getType() == OneTimeContribution::TYPE_FUNDING_BANK) {
             $bankInformationValidator = new BankInformationFormValidator($form->get('bankInformation'), $data->getBankInformation());
             $bankInformationValidator->validate();
             if (!$data->getStartTransferDate() instanceof \DateTime) {
                 $form->get('start_transfer_date_month')->addError(new FormError('Enter correct date.'));
             } else {
                 $minDate = new \DateTime('+5 days');
                 if ($data->getStartTransferDate() < $minDate) {
                     $form->get('start_transfer_date_month')->addError(new FormError("The start of your transfer should be at least 5 days after today’s date."));
                 }
             }
             if (!$data->getAmount()) {
                 $form->get('amount')->addError(new FormError('Required.'));
             }
             if ($form->has('transaction_frequency')) {
                 $frequency = $form->get('transaction_frequency')->getData();
                 if (null === $frequency || !is_numeric($frequency)) {
                     $form->get('transaction_frequency')->addError(new FormError('Choose an option.'));
                 }
             }
             if ($form->has('contribution_year')) {
                 $contributionYear = $data->getContributionYear();
                 if (null === $contributionYear || !is_numeric($contributionYear)) {
                     $form->get('contribution_year')->addError(new FormError('Enter valid year.'));
                 } else {
                     $currDate = new \DateTime();
                     $currYear = $currDate->format('Y');
                     $minDate = new \DateTime($currYear . '-01-01');
                     $maxDate = new \DateTime($currYear . '-04-15');
                     $startTransferDate = $data->getStartTransferDate();
                     if ($startTransferDate < $minDate || $startTransferDate > $maxDate) {
                         if ($contributionYear !== $currYear) {
                             $form->get('contribution_year')->addError(new FormError(sprintf('Value should be equal %s', $currYear)));
                         }
                     } else {
                         $prevYear = $currDate->add(\DateInterval::createFromDateString('-1 year'))->format('Y');
                         if ($contributionYear !== $currYear && $contributionYear !== $prevYear) {
                             $form->get('contribution_year')->addError(new FormError(sprintf('Value should be equal %s or %s', $prevYear, $currYear)));
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:junjinZ,项目名称:wealthbot,代码行数:50,代码来源:OneTimeContributionFormType.php

示例5: addFormError

 /**
  * @param FormInterface $form
  * @param FormException $formException
  */
 private static function addFormError(FormInterface $form, FormException $formException)
 {
     $fieldName = $formException->getFieldName();
     if ($form->has($fieldName)) {
         $form->get($fieldName)->addError(new FormError($formException->getMessage()));
     }
 }
开发者ID:HNKSoftware,项目名称:FrameworkBundle,代码行数:11,代码来源:FormExceptionHelper.php

示例6: getPostJsonData

 /**
  * Extracted POSTed data from JSON request
  *
  * @return array
  * @throws \Symfony\Component\HttpKernel\Exception\HttpException
  */
 protected function getPostJsonData()
 {
     $return = array();
     $body = $this->request->getContent();
     if (!empty($body) && !is_null($body) && $body != 'null') {
         $return = json_decode($body, true);
         if (null === $return || !is_array($return)) {
             throw new HttpException(400, "Bad JSON format of request body");
         }
     }
     // fix array type
     foreach ($return as $name => $value) {
         if (!$this->form->has($name)) {
             continue;
         }
         $formElement = $this->form->get($name);
         if ($formElement->getConfig()->getType()->getName() != 'collection') {
             continue;
         }
         if (!is_array($value) && !empty($value)) {
             $return[$name] = array($value);
         } elseif (!is_array($value) && empty($value)) {
             $return[$name] = array();
         }
     }
     // ignoring additional fields
     foreach ($return as $name => $value) {
         if (!$this->form->has($name)) {
             unset($return[$name]);
         }
     }
     return $return;
 }
开发者ID:keboola,项目名称:orchestrator-bundle,代码行数:39,代码来源:RestFormHandler.php

示例7: handleOpportunities

 /**
  * @param B2bCustomer $entity
  */
 protected function handleOpportunities(B2bCustomer $entity)
 {
     if ($this->form->has('opportunities')) {
         $opportunities = $this->form->get('opportunities');
         $this->appendOpportunities($entity, $opportunities->get('added')->getData());
         $this->removeOpportunities($entity, $opportunities->get('removed')->getData());
     }
 }
开发者ID:dairdr,项目名称:crm,代码行数:11,代码来源:B2bCustomerHandler.php

示例8: recurseErrors

 /**
  * Recurse over nested errors
  *
  * @param FormInterface $form
  * @param array $errors
  */
 private function recurseErrors(FormInterface $form, array $errors)
 {
     foreach ($errors as $field => $error) {
         if (is_array($error)) {
             $this->recurseErrors($form->has($field) ? $form->get($field) : $form, $error);
         } else {
             // todo: this fix should not be in here - needs lifting out into mapping
             if ('addressLine1' == $field) {
                 $field = 'street';
             }
             if ($form->has($field)) {
                 $form->get($field)->addError(new FormError($error));
                 unset($errors[$field]);
             }
         }
     }
 }
开发者ID:AlexEvesDeveloper,项目名称:hl-stuff,代码行数:23,代码来源:FormValidationErrorBinder.php

示例9: process

 /**
  * Process form
  *
  * @param CalendarEvent $entity
  *
  * @return bool True on successful processing, false otherwise
  */
 public function process(CalendarEvent $entity)
 {
     $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);
             }
             $this->onSuccess($entity);
             return true;
         }
     }
     return false;
 }
开发者ID:Maksold,项目名称:platform,代码行数:25,代码来源:SystemCalendarEventHandler.php

示例10: process

 /**
  * @param GridView $entity
  *
  * @return boolean
  */
 public function process(GridView $entity)
 {
     $entity->setFiltersData();
     $entity->setSortersData();
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $data = $this->request->request->all();
         unset($data['name']);
         if ($this->form->has('owner')) {
             $data['owner'] = $entity->getOwner();
         }
         $this->form->submit($data);
         if ($this->form->isValid()) {
             $this->onSuccess($entity);
             return true;
         }
     }
     return false;
 }
开发者ID:northdakota,项目名称:platform,代码行数:24,代码来源:GridViewApiHandler.php

示例11: password

 /**
  * @param FormInterface $form
  *
  * @return mixed
  */
 private static function password(FormInterface $form)
 {
     if ($form->has('credentials_group')) {
         $credentialsGroup = $form->get('credentials_group');
         if ($credentialsGroup->has('plainPassword')) {
             $plainPasswordElement = $credentialsGroup->get('plainPassword');
             if (!empty($plainPasswordElement->getData())) {
                 return 'CsrPassword';
             }
         }
     }
 }
开发者ID:transformcore,项目名称:csr-fast-stream-domain-model,代码行数:17,代码来源:Applicant.php

示例12: process

 /**
  * Process form
  *
  * @param  CalendarEvent $entity
  * @return bool  True on successful processing, false otherwise
  */
 public function process(CalendarEvent $entity)
 {
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $originalChildren = new ArrayCollection();
         foreach ($entity->getChildEvents() as $childEvent) {
             $originalChildren->add($childEvent);
         }
         $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);
             }
             $this->onSuccess($entity, $originalChildren, $this->form->get('notifyInvitedUsers')->getData());
             return true;
         }
     }
     return false;
 }
开发者ID:Maksold,项目名称:platform,代码行数:28,代码来源:CalendarEventApiHandler.php

示例13: buildValuesForm

 /**
  * {@inheritdoc}
  */
 public function buildValuesForm(FormInterface $form, FamilyInterface $family, DataInterface $data = null, array $options = [])
 {
     foreach ($family->getAttributes() as $attribute) {
         if ($attribute->getGroup()) {
             $groupName = $attribute->getGroup();
             if (!$form->has($groupName)) {
                 $form->add($groupName, 'form', ['inherit_data' => true]);
             }
             $this->addAttribute($form->get($groupName), $attribute, $family, $data, $options);
         } else {
             $this->addAttribute($form, $attribute, $family, $data, $options);
         }
     }
 }
开发者ID:VincentChalnot,项目名称:SidusEAVModelBundle,代码行数:17,代码来源:GroupedDataType.php

示例14: process

 /**
  * Process form
  *
  * @param  CalendarEvent $entity
  *
  * @throws \LogicException
  *
  * @return bool  True on successful processing, false otherwise
  */
 public function process(CalendarEvent $entity)
 {
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $originalChildren = new ArrayCollection();
         foreach ($entity->getChildEvents() as $childEvent) {
             $originalChildren->add($childEvent);
         }
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             $this->ensureCalendarSet($entity);
             // 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);
             }
             $targetEntityClass = $this->entityRoutingHelper->getEntityClassName($this->request);
             if ($targetEntityClass) {
                 $targetEntityId = $this->entityRoutingHelper->getEntityId($this->request);
                 $targetEntity = $this->entityRoutingHelper->getEntityReference($targetEntityClass, $targetEntityId);
                 $action = $this->entityRoutingHelper->getAction($this->request);
                 if ($action === 'activity') {
                     $this->activityManager->addActivityTarget($entity, $targetEntity);
                 }
                 if ($action === 'assign' && $targetEntity instanceof User && $targetEntityId !== $this->securityFacade->getLoggedUserId()) {
                     /** @var Calendar $defaultCalendar */
                     $defaultCalendar = $this->manager->getRepository('OroCalendarBundle:Calendar')->findDefaultCalendar($targetEntity->getId(), $targetEntity->getOrganization()->getId());
                     $entity->setCalendar($defaultCalendar);
                 }
             }
             $this->onSuccess($entity, $originalChildren, $this->form->get('notifyInvitedUsers')->getData());
             return true;
         }
     }
     return false;
 }
开发者ID:Maksold,项目名称:platform,代码行数:46,代码来源:CalendarEventHandler.php

示例15: chooseGroups

 /**
  * {@inheritdoc}
  */
 public function chooseGroups(FormInterface $form)
 {
     // All other fields are validated through the Default validation group
     $validation_groups = array('Default');
     if ($form->has('phone') && $form->has('mobile')) {
         $phoneData = $form->get('phone')->getData();
         $mobileData = $form->get('mobile')->getData();
         // 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';
             }
         }
     }
     if ($form->has('bankAccount') && $form->get('bankAccount')) {
         $sortCodeData = $form->get('bankAccount')->get('accountSortcode');
         $accountNumberData = $form->get('bankAccount')->get('accountNumber');
         // If either the sort code or account no are given,
         // validate both fields
         if (!empty($sortCodeData) || !empty($accountNumberData)) {
             $validation_groups[] = 'bankaccount';
         }
     }
     return $validation_groups;
 }
开发者ID:AlexEvesDeveloper,项目名称:hl-stuff,代码行数:39,代码来源:ReferencingApplicationValidationGroupSelector.php


注:本文中的Symfony\Component\Form\FormInterface::has方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。