Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
test-form-datamapper-errors
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maxime Veber
test-form-datamapper-errors
Commits
3e62c15c
Commit
3e62c15c
authored
5 years ago
by
Maxime Veber
Browse files
Options
Downloads
Patches
Plain Diff
Update heahdude example
Now working, type error catching was missing.
parent
34eea023
Branches
master
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Controller/TestHeahdudeController.php
+5
-15
5 additions, 15 deletions
src/Controller/TestHeahdudeController.php
with
5 additions
and
15 deletions
src/Controller/TestHeahdudeController.php
+
5
−
15
View file @
3e62c15c
...
...
@@ -47,34 +47,24 @@ class TestHeahdudeController extends AbstractController
$forms
=
iterator_to_array
(
$forms
);
try
{
$viewData
=
new
ParentModel
(
$forms
[
'content'
]
->
getData
(),
new
ColorVo
(
$forms
[
'color'
]
->
getData
()));
}
catch
(
InvalidColorException
$error
)
{
// What to do here ?!
// This does not work
// $forms['colorCondition']->setData(false);
// Even if it would, the error path is wrong!
}
// Catching all potential exception will result in null data in the form, which is ok.
}
catch
(
InvalidColorException
$error
)
{}
catch
(
\TypeError
$error
)
{}
}
})
->
add
(
'color'
,
ColorType
::
class
,
[
// Those constraints will act on form data, not view data. The form data remains not altered if there
// is an exception while processing the datamapper.
'constraints'
=>
[
new
Type
([
'type'
=>
'string'
]),
new
Callback
([
'callback'
=>
ColorVo
::
class
.
'::validateColor'
])
]
])
->
add
(
'content'
,
TextType
::
class
)
->
add
(
'colorCondition'
,
CheckboxType
::
class
,
[
'label'
=>
'Accept color'
,
'required'
=>
false
,
'mapped'
=>
false
,
'empty_data'
=>
true
,
'constraints'
=>
new
IsTrue
([
'message'
=>
'Wrong color input'
])
])
->
getForm
();
$form
->
submit
([
'color'
=>
10
,
'content'
=>
'foobar'
]);
dump
(
$form
->
getErrors
(
true
,
true
));
return
$this
->
json
([
'message'
=>
'Welcome to your new controller!'
,
'path'
=>
'src/Controller/TestVoFormController.php'
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment