Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
hasAnotherValidCommand example
public
function
preValidate
(
PostWriteValidationEvent
$event
)
: void
{
$writeException
=
$event
->
getExceptions
(
)
;
$commands
=
$event
->
getCommands
(
)
;
$violationList
=
new
ConstraintViolationList
(
)
;
foreach
(
$commands
as
$command
)
{
if
(
!
(
$command
instanceof InsertCommand
)
||
$command
->
getDefinition
(
)
->
getClass
(
)
!== LandingPageDefinition::
class
)
{
continue
;
}
if
(
!
$this
->
hasAnotherValidCommand
(
$commands
,
$command
)
)
{
$violationList
->
addAll
(
$this
->validator->
startContext
(
)
->
atPath
(
$command
->
getPath
(
)
. '/salesChannels'
)
->
validate
(
null,
[
new
NotBlank
(
)
]
)
->
getViolations
(
)
)
;
$writeException
->
add
(
new
WriteConstraintViolationException
(
$violationList
)
)
;
}
}
}