php Symfony-Component-Form-FormInterface类(方法)实例源码

下面列出了php Symfony-Component-Form-FormInterface 类(方法)源码代码实例,从而了解它的用法。

作者:it-blaste    项目:crop-bundl   
/**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $data = $form->getData();
     if (empty($data)) {
         $form->setData(array('left' => 0, 'top' => 0, 'width' => $options['width'], 'height' => $options['height'], 'min_width' => $options['width'], 'min_height' => $options['height']));
     }
 }

作者:loic42    项目:Syliu   
function it_builds_view(FormConfigInterface $config, FormView $view, FormInterface $form, FormInterface $prototype)
 {
     $form->getConfig()->willReturn($config);
     $config->getAttribute('prototypes')->willReturn(['configuration_kind' => $prototype]);
     $prototype->createView($view)->shouldBeCalled();
     $this->buildView($view, $form, []);
 }

作者:adam-paterso    项目:orocommerc   
/**
  * @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;
 }

作者:nany    项目:Syliu   
/**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $view->vars['feeCalculatorsConfigurations'] = array();
     foreach ($form->getConfig()->getAttribute('feeCalculatorsConfigurations') as $type => $feeCalculatorConfiguration) {
         $view->vars['feeCalculatorsConfigurations'][$type] = $feeCalculatorConfiguration->createView($view);
     }
 }

作者:ashutosh-srija    项目:findit_akene   
/**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     if ($form->getData() instanceof ProductValueInterface) {
         $this->productFormView->addChildren($form->getData(), $view);
     }
     $view->vars['mode'] = isset($options['block_config']['mode']) ? $options['block_config']['mode'] : 'normal';
 }

作者:AlexEvesDevelope    项目:hl-stuf   
/**
  * {@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');
 }

作者:nzzde    项目:SonataAdminBundl   
/**
  * @param \Symfony\Component\Form\FormView $view
  * @param \Symfony\Component\Form\FormInterface $form
  */
 public function buildView(FormView $view, FormInterface $form)
 {
     $sonataAdmin = $form->getAttribute('sonata_admin');
     // avoid to add extra information not required by non admin field
     if ($form->getAttribute('sonata_admin_enabled', true)) {
         $sonataAdmin['value'] = $form->getData();
         // add a new block types, so the Admin Form element can be tweaked based on the admin code
         $types = $view->get('types');
         $baseName = str_replace('.', '_', $sonataAdmin['field_description']->getAdmin()->getCode());
         $baseType = $types[count($types) - 1];
         $types[] = sprintf('%s_%s', $baseName, $baseType);
         $types[] = sprintf('%s_%s_%s', $baseName, $sonataAdmin['field_description']->getName(), $baseType);
         if ($sonataAdmin['block_name']) {
             $types[] = $sonataAdmin['block_name'];
         }
         $view->set('types', $types);
         $view->set('sonata_admin_enabled', true);
         $view->set('sonata_admin', $sonataAdmin);
         $attr = $view->get('attr', array());
         if (!isset($attr['class'])) {
             $attr['class'] = $sonataAdmin['class'];
         }
         $view->set('attr', $attr);
     } else {
         $view->set('sonata_admin_enabled', false);
     }
     $view->set('sonata_admin', $sonataAdmin);
 }

作者:GeneralMediaC    项目:GenemuFormBundl   
/**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $value = $form->getViewData();
     // set string representation
     if (true === $value) {
         $value = 'true';
     } elseif (false === $value) {
         $value = 'false';
     } elseif (null === $value) {
         $value = 'null';
     } elseif (is_array($value)) {
         $value = implode(', ', $value);
     } elseif ($value instanceof \DateTime) {
         $dateFormat = is_int($options['date_format']) ? $options['date_format'] : DateType::DEFAULT_FORMAT;
         $timeFormat = is_int($options['time_format']) ? $options['time_format'] : DateType::DEFAULT_FORMAT;
         $calendar = \IntlDateFormatter::GREGORIAN;
         $pattern = is_string($options['date_pattern']) ? $options['date_pattern'] : null;
         $formatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormat, $timeFormat, 'UTC', $calendar, $pattern);
         $formatter->setLenient(false);
         $value = $formatter->format($value);
     } elseif (is_object($value)) {
         if (method_exists($value, '__toString')) {
             $value = $value->__toString();
         } else {
             $value = get_class($value);
         }
     }
     $view->vars['value'] = (string) $value;
 }

作者:rdohm    项目:dms-filter-bundl   
/**
  * Navigates to the Root form to define if cascading should be done.
  *
  * @param FormInterface $form
  * @return boolean
  */
 public function getRootFormCascadeOption(FormInterface $form)
 {
     if (!$form->isRoot()) {
         return $this->getRootFormCascadeOption($form->getParent());
     }
     return $form->getConfig()->getOption('cascade_filter', false);
 }

作者:cyberm    项目:LexikTranslationBundl   
/**
  * {@inheritdoc}
  */
 public function process(FormInterface $form, Request $request)
 {
     $valid = false;
     if ($request->isMethod('POST')) {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $transUnit = $form->getData();
             $translations = $transUnit->filterNotBlankTranslations();
             // only keep translations with a content
             // link new translations to a file to be able to export them.
             foreach ($translations as $translation) {
                 if (!$translation->getFile()) {
                     $file = $this->fileManager->getFor(sprintf('%s.%s.yml', $transUnit->getDomain(), $translation->getLocale()), $this->rootDir . '/Resources/translations');
                     if ($file instanceof FileInterface) {
                         $translation->setFile($file);
                     }
                 }
             }
             if ($transUnit instanceof PropelTransUnit) {
                 // The setTranslations() method only accepts PropelCollections
                 $translations = new \PropelObjectCollection($translations);
             }
             $transUnit->setTranslations($translations);
             $this->storage->persist($transUnit);
             $this->storage->flush();
             $valid = true;
         }
     }
     return $valid;
 }

作者:RSSfee    项目:AdminBundl   
public function buildView(FormView $view, FormInterface $form, array $options)
 {
     //parent::buildView($view, $form, $options);
     $entity = $form->getParent()->getData();
     $property_name = $view->vars['name'];
     $this->defaults = array_merge($this->defaults, $options);
     // entity info
     $entity_info = $this->container->get('itf.admin_helper')->getEntityInfo(get_class($entity));
     $fk_entity_info = $this->container->get('itf.admin_helper')->getEntityInfo($this->defaults['data_class']);
     $this->defaults['fn_entity'] = $entity_info['entity_short'];
     $this->defaults['fn_bundle'] = $entity_info['bundle_short'];
     $this->defaults['fn_property'] = $property_name;
     $this->defaults['fn_fk_entity'] = $fk_entity_info['entity_short'];
     $this->defaults['fn_fk_bundle'] = $fk_entity_info['bundle_short'];
     // extract constraints
     $validator = $this->container->get('validator');
     $metadata = $validator->getMetadataFor($fk_entity_info['entity_fq']);
     if (isset($metadata->properties[$this->defaults['fn_entity_property']])) {
         $this->extractConstraints($metadata->properties[$this->defaults['fn_entity_property']]);
     }
     // set id
     if (method_exists($entity, 'getId')) {
         $this->defaults['fn_entity_id'] = (int) $entity->getId();
     }
     $view->vars = array_merge($view->vars, $this->defaults);
 }

作者:TeamNovate    项目:Syliu   
/**
  * @param FormInterface $form
  * @param string        $ruleType
  * @param array         $data
  */
 protected function addConfigurationFields(FormInterface $form, $ruleType, array $data = [])
 {
     /** @var RuleCheckerInterface $checker */
     $checker = $this->checkerRegistry->get($ruleType);
     $configurationField = $this->factory->createNamed('configuration', $checker->getConfigurationFormType(), $data, ['auto_initialize' => false]);
     $form->add($configurationField);
 }

作者:loic42    项目:Syliu   
function it_builds_view(FormView $view, FormInterface $form, FormConfigInterface $formConfig)
 {
     $form->getConfig()->shouldBeCalled()->willReturn($formConfig);
     $formConfig->getAttribute('prototypes')->shouldBeCalled()->willReturn(['type' => $form]);
     $form->createView($view)->shouldBeCalled();
     $this->buildView($view, $form, []);
 }

作者:nass5    项目:La   
/**
  * @param FormInterface     $form
  * @param array             $results
  *
  * @return array
  */
 private function formatFormErrors(FormInterface $form, &$results = array())
 {
     /*
      * first check if there are any errors bound for this element
      */
     $errors = $form->getErrors();
     if (count($errors)) {
         $messages = [];
         foreach ($errors as $error) {
             if ($error instanceof FormError) {
                 $messages[] = $this->translator->trans($error->getMessage(), $error->getMessageParameters(), 'validators');
             }
             $results[] = ['property_path' => $this->formatPropertyPath($error), 'message' => join(', ', $messages)];
         }
     }
     /*
      * Then, check if there are any children. If yes, then parse them
      */
     $children = $form->all();
     if (count($children)) {
         foreach ($children as $child) {
             if ($child instanceof FormInterface) {
                 $this->formatFormErrors($child, $results);
             }
         }
     }
     return $results;
 }

作者:Baudouin    项目:Aion-Rising-Back-en   
/**
  * @param \Symfony\Component\Form\FormView $view
  * @param \Symfony\Component\Form\FormInterface $form
  * @param array $options
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     if ($options['reload'] && !$options['as_url']) {
         throw new \InvalidArgumentException('GregwarCaptcha: The reload option cannot be set without as_url, see the README for more information');
     }
     $sessionKey = sprintf('gcb_%s', $form->getName());
     $isHuman = false;
     if ($options['humanity'] > 0) {
         $humanityKey = sprintf('%s_humanity', $sessionKey);
         if ($this->session->get($humanityKey, 0) > 0) {
             $isHuman = true;
         }
     }
     if ($options['as_url']) {
         $keys = $this->session->get($options['whitelist_key'], array());
         if (!in_array($sessionKey, $keys)) {
             $keys[] = $sessionKey;
         }
         $this->session->set($options['whitelist_key'], $keys);
         $options['session_key'] = $sessionKey;
     }
     $view->vars = array_merge($view->vars, array('captcha_width' => $options['width'], 'captcha_height' => $options['height'], 'reload' => $options['reload'], 'image_id' => uniqid('captcha_'), 'captcha_code' => $this->generator->getCaptchaCode($options), 'value' => '', 'is_human' => $isHuman));
     $persistOptions = array();
     foreach (array('phrase', 'width', 'height', 'distortion', 'length', 'quality', 'background_color', 'text_color') as $key) {
         $persistOptions[$key] = $options[$key];
     }
     $this->session->set($sessionKey, $persistOptions);
 }

作者:aulasoftwarelibr    项目:ritsig   
private function addUniversityForm(FormInterface $form, $university)
 {
     $form->add($this->factory->createNamed('university', 'entity', $university, array('class' => 'AppBundle:University', 'mapped' => false, 'auto_initialize' => false, 'label' => 'label.university', 'placeholder' => 'placeholder.university', 'query_builder' => function (EntityRepository $repository) {
         $qb = $repository->createQueryBuilder('university')->orderBy('university.name', 'ASC');
         return $qb;
     })));
 }

作者:ahmadrabi    项目:Syliu   
/**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $view->vars['prototypes'] = [];
     foreach ($form->getConfig()->getAttribute('prototypes') as $type => $prototype) {
         $view->vars['prototypes'][$type] = $prototype->createView($view);
     }
 }

作者:j0ssG    项目:VichUploaderBundl   
/**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $view->vars['object'] = $form->getParent()->getData();
     if ($options['download_link'] && $view->vars['object']) {
         $view->vars['download_uri'] = $this->storage->resolveUri($form->getParent()->getData(), $form->getName());
     }
 }

作者:pr0code    项目:Inkstan   
/**
  * {@inheritdoc}
  *
  * @param FormView      $view
  * @param FormInterface $form
  * @param array         $options
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     if ($form->count() == 0) {
         return;
     }
     array_map(array($this, 'validateButton'), $form->all());
 }

作者:nyroDe    项目:NyroCmsBundl   
/**
  * Pass the image URL to the view.
  *
  * @param FormView      $view
  * @param FormInterface $form
  * @param array         $options
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $data = $form->getParent()->getData();
     if ($data instanceof ContentSpec) {
         $tmpName = explode('_', $form->getName());
         if (count($tmpName) === 3) {
             $currentFile = null;
             foreach ($data->getTranslations() as $tr) {
                 if ($tr->getLocale() == $tmpName[1] && ($tr->getField() == 'content' || $tr->getField() == 'data')) {
                     $contents = json_decode($tr->getContent(), true);
                     if (isset($contents[$tmpName[2]])) {
                         $currentFile = $contents[$tmpName[2]];
                     }
                 }
             }
         } else {
             $currentFile = $data->getInContent($form->getName());
             if (!$currentFile) {
                 $currentFile = $data->getInData($form->getName());
             }
         }
         if ($currentFile) {
             $currentFileWeb = $this->nyrocms->getHandler($data->getContentHandler())->getUploadDir() . '/' . $currentFile;
             $view->vars['currentFile'] = $currentFileWeb;
             $view->vars['showDelete'] = $options['showDelete'] && is_string($options['showDelete']) ? $options['showDelete'] : false;
         }
     }
 }


问题


面经


文章

微信
公众号

扫码关注公众号