本文整理汇总了PHP中Symfony\Component\Form\FormInterface::all方法的典型用法代码示例。如果您正苦于以下问题:PHP FormInterface::all方法的具体用法?PHP FormInterface::all怎么用?PHP FormInterface::all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormInterface
的用法示例。
在下文中一共展示了FormInterface::all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: serializeForm
private function serializeForm(FormInterface $form)
{
if (!$form->all()) {
return $form->getViewData();
}
$data = null;
foreach ($form->all() as $child) {
$name = $child->getConfig()->getName();
$data[$name] = $this->serializeForm($child);
}
return $data;
}
示例2: testSubmit
/**
* @dataProvider getValidInputs
*/
public function testSubmit($submitted, $expected)
{
$this->sut->submit($submitted);
$msg = '';
if (!$this->sut->isValid()) {
$msg = print_r($this->sut->getErrors(), true);
foreach ($this->sut->all() as $child) {
$msg .= "\n" . print_r($child->getErrors(), true);
}
}
$this->assertTrue($this->sut->isValid(), $msg);
$this->assertEquals($expected, $this->sut->getData());
}
示例3: interactWith
public function interactWith(FormInterface $form, HelperSet $helperSet, InputInterface $input, OutputInterface $output)
{
if (!$form->isRoot()) {
throw new CanNotInteractWithForm('This interactor only works with root forms');
}
if ($input->isInteractive()) {
throw new CanNotInteractWithForm('This interactor only works with non-interactive input');
}
/*
* We need to adjust the input values for repeated types by copying the provided value to both of the repeated
* fields. We only loop through the top-level fields, since there are no command options for deeper lying fields
* anyway.
*
* The fix was provided by @craigh
*
* P.S. If we need to add another fix like this, we should move this out to dedicated "input fixer" classes.
*/
foreach ($form->all() as $child) {
$config = $child->getConfig();
$name = $child->getName();
if ($config->getType()->getInnerType() instanceof RepeatedType && $input->hasOption($name)) {
$input->setOption($name, [$config->getOption('first_name') => $input->getOption($name), $config->getOption('second_name') => $input->getOption($name)]);
}
}
// use the original input as the submitted data
return $input;
}
示例4: mergeConstraints
/**
* Merges constraints from the form with constraints in the class metaData
*
* @param FormInterface $form
*/
public function mergeConstraints(FormInterface &$form)
{
$metaData = null;
$dataClass = $form->getConfig()->getDataClass();
if ($dataClass != '') {
$metaData = $this->validator->getMetadataFor($dataClass);
}
if ($metaData instanceof ClassMetadata) {
/**
* @var FormInterface $child
*/
foreach ($form->all() as $child) {
$options = $child->getConfig()->getOptions();
$name = $child->getConfig()->getName();
$type = $child->getConfig()->getType()->getName();
if (isset($options['constraints'])) {
$existingConstraints = $options['constraints'];
$extractedConstraints = $this->extractPropertyConstraints($name, $metaData);
// Merge all constraints
$options['constraints'] = array_merge($existingConstraints, $extractedConstraints);
}
$form->add($name, $type, $options);
}
}
}
示例5: transform
public function transform(FormInterface $form, $extensions = [])
{
$data = [];
$order = 1;
$required = [];
foreach ($form->all() as $name => $field) {
$transformedChild = $this->resolver->resolve($field)->transform($field, $extensions);
$transformedChild['propertyOrder'] = $order;
$data[$name] = $transformedChild;
$order++;
if ($this->resolver->resolve($field)->isRequired($field)) {
$required[] = $field->getName();
}
}
$schema = ['title' => $form->getConfig()->getOption('label'), 'type' => 'object', 'properties' => $data];
if (!empty($required)) {
$schema['required'] = $required;
}
$innerType = $form->getConfig()->getType()->getInnerType();
if (method_exists($innerType, 'buildLiform')) {
$schema['liform'] = $innerType->buildLiform($form);
}
$this->addCommonSpecs($form, $schema, $extensions);
return $schema;
}
示例6: 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;
}
示例7: buildView
/**
* {@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'];
}
示例8: buildView
/**
* {@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());
}
示例9: getErrorMessages
/**
* Returns an array with form fields errors
*
* @param FormInterface $form
* @param bool|false $useLabels
* @param array $errors
* @return array
*/
public function getErrorMessages(FormInterface $form, $useLabels = false, $errors = array())
{
if ($form->count() > 0) {
foreach ($form->all() as $child) {
if (!$child->isValid()) {
$errors = $this->getErrorMessages($child, $useLabels, $errors);
}
}
}
foreach ($form->getErrors() as $error) {
if ($useLabels) {
$fieldNameData = $this->getErrorFormLabel($form);
} else {
$fieldNameData = $this->getErrorFormId($form);
}
$fieldName = $fieldNameData;
if ($useLabels) {
/**
* @ignore
*/
$fieldName = $this->translator->trans($fieldNameData['label'], array(), $fieldNameData['domain']);
}
$errors[$fieldName] = $error->getMessage();
}
return $errors;
}
示例10: finishView
public function finishView(FormView $view, FormInterface $form, array $options)
{
foreach ($form->all() as $identifier => $child) {
if (false === $child->getConfig()->getOption('serialize_only')) {
continue;
}
unset($view->children[$identifier]);
}
}
示例11: __construct
public function __construct(FormInterface $form)
{
$this->name = $form->getName();
foreach ($form->getErrors() as $error) {
$this->errors[] = $error;
}
foreach ($form->all() as $child) {
$this->children[] = new static($child);
}
}
示例12: convertInputToSubmittedData
/**
* @param InputInterface $input
* @param FormInterface $form
*
* @return array
*/
private function convertInputToSubmittedData(InputInterface $input, FormInterface $form)
{
$submittedData = [];
// we don't need to do this recursively, since command options are one-dimensional (or are they?)
foreach ($form->all() as $name => $field) {
if ($input->hasOption($name)) {
$submittedData[$name] = $input->getOption($name);
}
}
return $submittedData;
}
开发者ID:bangpound,项目名称:symfony-console-form,代码行数:17,代码来源:UseInputOptionsAsEventDataEventSubscriber.php
示例13: getFormChildErrorMessages
/**
* @param FormInterface $form
* @return array
*/
protected function getFormChildErrorMessages(FormInterface $form)
{
$errors = [];
foreach ($form->all() as $child) {
if (!empty($child) && !$child->isValid()) {
foreach ($this->getErrorMessages($child) as $error) {
$errors[] = $error;
}
}
}
return $errors;
}
示例14: getFormChildErrorMessages
/**
* @param FormInterface $form
* @return array
*/
protected function getFormChildErrorMessages(FormInterface $form)
{
$errors = [];
foreach ($form->all() as $child) {
if ($this->shouldAddChildErrorMessage($child)) {
foreach ($this->getErrorMessages($child) as $error) {
$errors[] = $error;
}
}
}
return $errors;
}
示例15: getFullAddress
/**
* @param mixed $data
* @param FormInterface $form
*
* @return mixed
*
* @throws \InvalidArgumentException
*/
public function getFullAddress($data, FormInterface $form)
{
$fields = array();
foreach ($form->all() as $field) {
$options = $field->getConfig()->getOptions();
if (isset($options['geo_code_field']) && true == $options['geo_code_field']) {
$fields[] = $data[$field->getName()];
}
}
if (count($fields)) {
return implode(' ', $fields);
}
throw new \InvalidArgumentException('GeoDataAdapter address field mismatch');
}