本文整理汇总了PHP中Symfony\Component\Form\FormInterface类的典型用法代码示例。如果您正苦于以下问题:PHP FormInterface类的具体用法?PHP FormInterface怎么用?PHP FormInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FormInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildView
/**
* {@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']));
}
}
示例2:
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, []);
}
示例3: 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;
}
示例4: buildView
/**
* {@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);
}
}
示例5: buildView
/**
* {@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';
}
示例6: 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');
}
示例7: buildView
/**
* @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);
}
示例8: buildView
/**
* {@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;
}
示例9: getRootFormCascadeOption
/**
* 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);
}
示例10: process
/**
* {@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;
}
示例11: buildView
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);
}
示例12: addConfigurationFields
/**
* @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);
}
示例13:
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, []);
}
示例14: formatFormErrors
/**
* @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;
}
示例15: buildView
/**
* @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);
}