8000 [Form] Enhanced the form error message by Burgov · Pull Request #4557 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] Enhanced the form error message #4557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/Symfony/Component/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,25 +348,27 @@ public function setData($modelData)
if (!empty($viewData)) {
$dataClass = $this->config->getDataClass();

$actualType = is_object($viewData) ? 'an instance of class ' . get_class($viewData) : ' a(n) ' . gettype($viewData);

if (null === $dataClass && is_object($viewData) && !$viewData instanceof \ArrayAccess) {
$expectedType = 'scalar, array or an instance of \ArrayAccess';

throw new FormException(
'The form\'s view data is expected to be of type ' . $expectedType . ', ' .
'but is an instance of class ' . get_class($viewData) . '. You ' .
'but is ' . $actualType . '. You ' .
'can avoid this error by setting the "data_class" option to ' .
'"' . get_class($viewData) . '" or by adding a view transformer ' .
'that transforms ' . get_class($viewData) . ' to ' . $expectedType . '.'
'that transforms ' . $actualType . ' to ' . $expectedType . '.'
);
}

if (null !== $dataClass && !$viewData instanceof $dataClass) {
throw new FormException(
'The form\'s view data is expected to be an instance of class ' .
$dataClass . ', but has the type ' . gettype($viewData) . '. You ' .
'can avoid this error by setting the "data_class" option to ' .
'null or by adding a view transformer that transforms ' .
gettype($viewData) . ' to ' . $dataClass . '.'
$dataClass . ', but is '. $actualType . '. You can avoid this error ' .
'by setting the "data_class" option to null or by adding a view ' .
'transformer that transforms ' . $actualType . ' to an instance of ' .
$dataClass . '.'
);
}
}
Expand Down
0