本文整理汇总了PHP中Symfony\Component\Form\FormInterface::getData方法的典型用法代码示例。如果您正苦于以下问题:PHP FormInterface::getData方法的具体用法?PHP FormInterface::getData怎么用?PHP FormInterface::getData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormInterface
的用法示例。
在下文中一共展示了FormInterface::getData方法的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: buildView
public function buildView(FormView $view, FormInterface $form, array $options)
{
$center = new GMapsCoordinate($form->getData()->getLatitude(), $form->getData()->getLongitude());
$this->map->setCenter($center);
$this->map->setMapOption('zoom', 10);
$view->vars['map'] = $this->map;
}
示例3: buildView
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['object'] = $form->getData();
if ($options['download_link'] && $view->vars['object']) {
$view->vars['download_uri'] = $this->storage->resolveUri($form->getData(), 'file');
}
}
示例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: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$vars = ['configs' => $options['configs']];
if ($form->getData()) {
$data = $form->getParent()->getData();
$fieldConfig = $this->cm->getProvider('extend')->getConfig($data, $form->getName());
if ($form->getData()) {
/** @var ConverterInterface|EntitySelectHandler $converter */
$converter = $options['converter'];
$result = [];
if ($converter instanceof EntitySelectHandler) {
$converter->initForEntity($fieldConfig->getId()->getClassName(), $fieldConfig->get('target_field'));
}
if (isset($options['configs']['multiple']) && $options['configs']['multiple']) {
foreach ($form->getData() as $item) {
$result[] = $converter->convertItem($item);
}
} else {
$result[] = $converter->convertItem($form->getData());
}
$vars['attr'] = ['data-selected-data' => json_encode($result)];
}
}
$view->vars = array_replace_recursive($view->vars, $vars);
}
示例6: 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;
}
示例7: extractSubmittedData
/**
* {@inheritdoc}
*/
public function extractSubmittedData(FormInterface $form)
{
$data = array('submitted_data' => array('norm' => $this->valueExporter->exportValue($form->getNormData())), 'errors' => array());
if ($form->getViewData() !== $form->getNormData()) {
$data['submitted_data']['view'] = $this->valueExporter->exportValue($form->getViewData());
}
if ($form->getData() !== $form->getNormData()) {
$data['submitted_data']['model'] = $this->valueExporter->exportValue($form->getData());
}
foreach ($form->getErrors() as $error) {
$errorData = array('message' => $error->getMessage(), 'origin' => is_object($error->getOrigin()) ? spl_object_hash($error->getOrigin()) : null, 'trace' => array());
$cause = $error->getCause();
while (null !== $cause) {
if ($cause instanceof ConstraintViolationInterface) {
$errorData['trace'][] = array('class' => $this->valueExporter->exportValue(get_class($cause)), 'root' => $this->valueExporter->exportValue($cause->getRoot()), 'path' => $this->valueExporter->exportValue($cause->getPropertyPath()), 'value' => $this->valueExporter->exportValue($cause->getInvalidValue()));
$cause = method_exists($cause, 'getCause') ? $cause->getCause() : null;
continue;
}
if ($cause instanceof \Exception) {
$errorData['trace'][] = array('class' => $this->valueExporter->exportValue(get_class($cause)), 'message' => $this->valueExporter->exportValue($cause->getMessage()));
$cause = $cause->getPrevious();
continue;
}
$errorData['trace'][] = $cause;
break;
}
$data['errors'][] = $errorData;
}
$data['synchronized'] = $this->valueExporter->exportValue($form->isSynchronized());
return $data;
}
示例8: 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';
}
示例9: getData
/**
* {@inheritdoc}
*/
public function getData()
{
$data = array('form' => $this->form->createView(), 'element' => $this->element);
if ($this->form->getData()) {
$data['id'] = $this->element->getDataIndexer()->getIndex($this->form->getData());
}
return $data;
}
示例10: getResourceNode
/**
* Get resource node.
*/
private function getResourceNode(FormInterface $form)
{
if ($form->getData() instanceof ResourceNode) {
return $form->getData();
} elseif ($form->getData() && $form->getData() != '') {
return $this->resourceManager->getById($form->getData());
}
}
示例11: handle
/**
* @param FormInterface $form
* @param Request $request
* @param array $options
*
* @return bool
*/
public function handle(FormInterface $form, Request $request, array $options = null)
{
$form->handleRequest($request);
if (!$form->isValid()) {
return false;
}
$this->handler->updateCredentials($form->getData()->getUser(), $form->getData()->getNewPassword());
return true;
}
示例12: 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());
}
示例13: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$vars = array('configs' => $options['configs']);
if ($form->getData()) {
$fieldConfig = $this->entityManager->getExtendManager()->getConfigProvider()->getConfig($form->getParent()->getData(), $form->getName());
$fieldName = $fieldConfig->get('target_field');
$vars['attr'] = array('data-entities' => json_encode(array(array($fieldName => $form->getData()->{'get' . ucfirst($fieldName)}()))));
}
$view->vars = array_replace_recursive($view->vars, $vars);
}
示例14: process
/**
* @param Quote $quote
* @return Order|null
*/
public function process(Quote $quote)
{
$this->form->setData($quote);
if ($this->request->isMethod('POST')) {
$this->form->submit($this->request);
if ($this->form->isValid()) {
return $this->onSuccess($quote, $this->form->getData());
}
}
return null;
}
示例15: buildView
public function buildView(FormView $view, FormInterface $form, array $options)
{
$filename = $options['image_filename'] ?: (!is_null($form->getData()) ? $form->getData()->getHGFile()->getFilOriginalFilename() : '');
$size = $this->fileManager->sizeExistsForType($options['repository_type'], $options['image_preview_size']) ? $options['image_preview_size'] : null;
$view->vars['image_filename'] = $filename;
$view->vars['delete_link_class'] = $options['delete_link_class'];
$view->vars['delete_link_type'] = $options['delete_link_type'];
$view->vars['delete_link_text'] = $options['delete_link_text'];
$view->vars['image_preview_class'] = $options['image_preview_class'];
$view->vars['image_preview_size'] = $size;
$view->vars['template'] = $options['template'];
}