Skip to content

Commit

Permalink
Check if subject is available to avoid error in PropertyAccessor
Browse files Browse the repository at this point in the history
  • Loading branch information
pulzarraider committed Aug 9, 2015
1 parent a0801f1 commit 5c08def
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions Form/Type/AdminType.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,27 @@ public function buildForm(FormBuilderInterface $builder, array $options)
if ($builder->getData() === null) {
$p = new PropertyAccessor(false, true);
try {
// for PropertyAccessor < 2.5
// @todo remove this code for old PropertyAccessor after dropping support for Symfony 2.3
if (!method_exists($p, 'isReadable')) {
$subjectCollection = $p->getValue(
$admin->getParentFieldDescription()->getAdmin()->getSubject(),
$this->getFieldDescription($options)->getFieldName()
);
if ($subjectCollection instanceof Collection) {
$subject = $subjectCollection->get(trim($options['property_path'], '[]'));
$parentSubject = $admin->getParentFieldDescription()->getAdmin()->getSubject();
if ($parentSubject !== null && $parentSubject !== false) {
// for PropertyAccessor < 2.5
// @todo remove this code for old PropertyAccessor after dropping support for Symfony 2.3
if (!method_exists($p, 'isReadable')) {
$subjectCollection = $p->getValue(
$parentSubject,
$this->getFieldDescription($options)->getFieldName()
);
if ($subjectCollection instanceof Collection) {
$subject = $subjectCollection->get(trim($options['property_path'], '[]'));
}
} else {
// for PropertyAccessor >= 2.5
$subject = $p->getValue(
$parentSubject,
$this->getFieldDescription($options)->getFieldName().$options['property_path']
);
}
} else {
// for PropertyAccessor >= 2.5
$subject = $p->getValue(
$admin->getParentFieldDescription()->getAdmin()->getSubject(),
$this->getFieldDescription($options)->getFieldName().$options['property_path']
);
$builder->setData($subject);
}
$builder->setData($subject);
} catch (NoSuchIndexException $e) {
// no object here
}
Expand Down

0 comments on commit 5c08def

Please sign in to comment.