Browse Source

Merge pull request #3163 from pulzarraider/subject_check

Check if subject is available in AdminType to avoid error in PropertyAccessor
Andrej Hudec 9 years ago
parent
commit
59bf1d5e46
1 changed files with 19 additions and 16 deletions
  1. 19 16
      Form/Type/AdminType.php

+ 19 - 16
Form/Type/AdminType.php

@@ -54,24 +54,27 @@ class AdminType extends AbstractType
         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
             }