Skip to content

Commit

Permalink
Add Collection check.
Browse files Browse the repository at this point in the history
Check if it's ArrayAccess or array.
Fixes sonata-project#7538.
  • Loading branch information
TheFox committed Oct 15, 2021
1 parent 63fa433 commit 627d0c8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Admin/AdminHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ public function appendFormFieldElement(AdminInterface $admin, $subject, $element

$collection = $this->propertyAccessor->getValue($subject, $path);

if (!($collection instanceof \ArrayAccess) && !is_array($collection)) {
throw new \TypeError(sprintf(
'Collection must be an instance of %s or array, %s given.',
\ArrayAccess::class,
\is_object($collection) ? 'instance of "'.\get_class($collection).'"' : '"'.\gettype($collection).'"'
));
}

$modelClassName = $this->getEntityClassName(
$admin,
explode('.', preg_replace('#\[\d*?]#', '', $path))
Expand Down

0 comments on commit 627d0c8

Please sign in to comment.