/**
  * {@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']));
     }
 }
 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, []);
 }
 /**
  * @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;
 }
Beispiel #4
0
 /**
  * {@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);
     }
 }
 /**
  * {@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';
 }
 /**
  * {@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');
 }
 /**
  * Process form
  *
  * @param  EmailTemplate $entity
  *
  * @return bool True on successful processing, false otherwise
  */
 public function process(EmailTemplate $entity)
 {
     // always use default locale during template edit in order to allow update of default locale
     $entity->setLocale($this->defaultLocale);
     if ($entity->getId()) {
         // refresh translations
         $this->manager->refresh($entity);
     }
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         // deny to modify system templates
         if ($entity->getIsSystem() && !$entity->getIsEditable()) {
             $this->form->addError(new FormError($this->translator->trans('oro.email.handler.attempt_save_system_template')));
             return false;
         }
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             // mark an email template creating by an user as editable
             if (!$entity->getId()) {
                 $entity->setIsEditable(true);
             }
             $this->manager->persist($entity);
             $this->manager->flush();
             return true;
         }
     }
     return false;
 }
 /**
  * @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);
 }
 /**
  * {@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;
 }
 public function testProcessInvalid()
 {
     $this->request->setMethod('POST');
     $this->form->expects($this->once())->method('setData')->with($this->entity);
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(false));
     $this->assertFalse($this->handler->process($this->entity));
 }
 /**
  * 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);
 }
 /**
  * {@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;
 }
 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);
 }
 /**
  * @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);
 }
 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, []);
 }
Beispiel #16
0
 /**
  * @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;
 }
 /**
  * @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);
 }
 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;
     })));
 }
 /**
  * {@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);
     }
 }
 /**
  * {@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());
     }
 }
Beispiel #21
0
 /**
  * {@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());
 }
 /**
  * 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;
         }
     }
 }
Beispiel #23
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form)
 {
     $view->set('value', $form->getAttribute('value'))->set('checked', (bool) $form->getClientData());
     if ($view->hasParent()) {
         $view->set('full_name', $view->getParent()->get('full_name'));
     }
 }
 /**
  * @param FormView $view
  * @param FormInterface $form
  * @param array $options
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     /** @var ProductionPlanEditDTO $data */
     $data = $form->getData();
     $view->vars['dateString'] = $data->dateString;
     $view->vars['workingShiftsDisplayNames'] = $data->workingShiftsDisplayNames;
 }
 /**
  * @param FormView      $view
  * @param FormInterface $form
  * @param array         $options
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $sonataAdmin = $form->getConfig()->getAttribute('sonata_admin');
     $sonataAdminHelp = isset($options['sonata_help']) ? $options['sonata_help'] : null;
     // avoid to add extra information not required by non admin field
     if ($sonataAdmin && $form->getConfig()->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
         $block_prefixes = $view->vars['block_prefixes'];
         $baseName = str_replace('.', '_', $sonataAdmin['admin']->getCode());
         $baseType = $block_prefixes[count($block_prefixes) - 2];
         $blockSuffix = preg_replace('#^_([a-z0-9]{14})_(.++)$#', '$2', array_pop($block_prefixes));
         $block_prefixes[] = sprintf('%s_%s', $baseName, $baseType);
         $block_prefixes[] = sprintf('%s_%s_%s', $baseName, $sonataAdmin['name'], $baseType);
         $block_prefixes[] = sprintf('%s_%s_%s_%s', $baseName, $sonataAdmin['name'], $baseType, $blockSuffix);
         if (isset($sonataAdmin['block_name']) && $sonataAdmin['block_name'] !== false) {
             $block_prefixes[] = $sonataAdmin['block_name'];
         }
         $view->vars['block_prefixes'] = $block_prefixes;
         $view->vars['sonata_admin_enabled'] = true;
         $view->vars['sonata_admin'] = $sonataAdmin;
         $attr = $view->vars['attr'];
         if (!isset($attr['class']) && isset($sonataAdmin['class'])) {
             $attr['class'] = $sonataAdmin['class'];
         }
         $view->vars['attr'] = $attr;
     } else {
         $view->vars['sonata_admin_enabled'] = false;
     }
     $view->vars['sonata_help'] = $sonataAdminHelp;
     $view->vars['sonata_admin'] = $sonataAdmin;
 }
Beispiel #26
0
 /**
  * {@inheritdoc}
  */
 public function finishView(FormView $view, FormInterface $form, array $options)
 {
     $view->vars['widget'] = $options['widget'];
     // Change the input to a HTML5 date input if
     //  * the widget is set to "single_text"
     //  * the format matches the one expected by HTML5
     if ('single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) {
         $view->vars['type'] = 'date';
     }
     if ($form->getConfig()->hasAttribute('formatter')) {
         $pattern = $form->getConfig()->getAttribute('formatter')->getPattern();
         // remove special characters unless the format was explicitly specified
         if (!is_string($options['format'])) {
             $pattern = preg_replace('/[^yMd]+/', '', $pattern);
         }
         // set right order with respect to locale (e.g.: de_DE=dd.MM.yy; en_US=M/d/yy)
         // lookup various formats at http://userguide.icu-project.org/formatparse/datetime
         if (preg_match('/^([yMd]+)[^yMd]*([yMd]+)[^yMd]*([yMd]+)$/', $pattern)) {
             $pattern = preg_replace(array('/y+/', '/M+/', '/d+/'), array('{{ year }}', '{{ month }}', '{{ day }}'), $pattern);
         } else {
             // default fallback
             $pattern = '{{ year }}{{ month }}{{ day }}';
         }
         $view->vars['date_pattern'] = $pattern;
     }
 }
 /**
  * @param FormInterface $form
  * @param UserEmailOrigin $emailOrigin
  */
 protected function updateForm(FormInterface $form, UserEmailOrigin $emailOrigin)
 {
     if (!empty($emailOrigin->getAccessToken())) {
         $form->add('checkFolder', 'button', ['label' => $this->translator->trans('oro.email.retrieve_folders.label'), 'attr' => ['class' => 'btn btn-primary']])->add('folders', 'oro_email_email_folder_tree', ['label' => $this->translator->trans('oro.email.folders.label'), 'attr' => ['class' => 'folder-tree'], 'tooltip' => $this->translator->trans('oro.email.folders.tooltip')]);
         $form->remove('check');
     }
 }
 /**
  * {@inheritDoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $children = $form->all();
     $view->vars['value']['type'] = $children['type']->getViewData();
     $view->vars['value']['value'] = $children['value']->getViewData();
     $view->vars['show_filter'] = $options['show_filter'];
 }
Beispiel #29
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $view->vars['valid'] = $valid = !$form->isSubmitted() || $form->isValid();
     $view->vars['icon'] = $valid ? $options['icon'] : $options['error_icon'];
     $view->vars['tab_active'] = false;
     $view->parent->vars['vic_tabbed'] = true;
 }
Beispiel #30
0
 /**
  * Process form
  *
  * @param  Call $entity
  *
  * @return bool  True on successful processing, false otherwise
  */
 public function process(Call $entity)
 {
     $targetEntityClass = $this->request->get('entityClass');
     $targetEntityId = $this->request->get('entityId');
     $options = [];
     if ($targetEntityClass && $this->request->getMethod() === 'GET') {
         $targetEntity = $this->entityRoutingHelper->getEntity($targetEntityClass, $targetEntityId);
         if (!$entity->getId()) {
             $entity->setPhoneNumber($this->phoneProvider->getPhoneNumber($targetEntity));
         }
         $options = ['phone_suggestions' => array_unique(array_map(function ($item) {
             return $item[0];
         }, $this->phoneProvider->getPhoneNumbers($targetEntity)))];
     }
     $this->form = $this->formFactory->createNamed($this->formName, $this->formType, $entity, $options);
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             if ($targetEntityClass) {
                 $targetEntity = $this->entityRoutingHelper->getEntity($targetEntityClass, $targetEntityId);
                 $this->callActivityManager->addAssociation($entity, $targetEntity);
                 $phones = $this->phoneProvider->getPhoneNumbers($targetEntity);
                 foreach ($phones as $phone) {
                     if ($entity->getPhoneNumber() === $phone[0]) {
                         $this->callActivityManager->addAssociation($entity, $phone[1]);
                     }
                 }
             }
             $this->onSuccess($entity);
             return true;
         }
     }
     return false;
 }