Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getErrorBubbling example
->
add
(
'foo',
static
::TESTED_TYPE
)
->
getForm
(
)
->
createView
(
)
;
$this
->
assertFalse
(
$view
->
isRendered
(
)
)
;
}
public
function
testErrorBubblingIfCompound
(
)
{
$form
=
$this
->factory->
create
(
static
::TESTED_TYPE
)
;
$this
->
assertTrue
(
$form
->
getConfig
(
)
->
getErrorBubbling
(
)
)
;
}
public
function
testNoErrorBubblingIfNotCompound
(
)
{
$form
=
$this
->factory->
create
(
static
::TESTED_TYPE, null,
[
'compound' => false,
]
)
;
$this
->
assertFalse
(
$form
->
getConfig
(
)
->
getErrorBubbling
(
)
)
;
}
return
$this
;
}
public
function
addError
(
FormError
$error
)
:
static
{
if
(
null ===
$error
->
getOrigin
(
)
)
{
$error
->
setOrigin
(
$this
)
;
}
if
(
$this
->parent &&
$this
->config->
getErrorBubbling
(
)
)
{
$this
->parent->
addError
(
$error
)
;
}
else
{
$this
->errors
[
]
=
$error
;
}
return
$this
;
}
public
function
isSubmitted
(
)
: bool
{
return
$this
->submitted;
}
while
(
$this
->
acceptsErrors
(
$scope
)
&&
isset
(
$mapping
[
'.'
]
)
)
{
$dotRule
=
new
MappingRule
(
$scope
, '.',
$mapping
[
'.'
]
)
;
$scope
=
$dotRule
->
getTarget
(
)
;
$mapping
=
$scope
->
getConfig
(
)
->
getOption
(
'error_mapping'
)
;
}
// Only add the error if the form is synchronized
if
(
$this
->
acceptsErrors
(
$scope
)
)
{
if
(
$violation
->
getConstraint
(
)
instanceof File &&
(string)
\UPLOAD_ERR_INI_SIZE ===
$violation
->
getCode
(
)
)
{
$errorsTarget
=
$scope
;
while
(
null !==
$errorsTarget
->
getParent
(
)
&&
$errorsTarget
->
getConfig
(
)
->
getErrorBubbling
(
)
)
{
$errorsTarget
=
$errorsTarget
->
getParent
(
)
;
}
$errors
=
$errorsTarget
->
getErrors
(
)
;
$errorsTarget
->
clearErrors
(
)
;
foreach
(
$errors
as
$error
)
{
if
(
!
$error
instanceof FileUploadError
)
{
$errorsTarget
->
addError
(
$error
)
;
}
}
}