Explorar o código

Fixed issue when multiple sub-admins were added in form building

Hugo Briand %!s(int64=10) %!d(string=hai) anos
pai
achega
bf2ca5b6b8
Modificáronse 2 ficheiros con 5 adicións e 6 borrados
  1. 2 2
      Admin/Admin.php
  2. 3 4
      Form/Type/AdminType.php

+ 2 - 2
Admin/Admin.php

@@ -1005,7 +1005,7 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      */
     public function getClass()
     {
-        if ($this->hasSubject()) {
+        if ($this->hasSubject() && is_object($this->getSubject())) {
             return ClassUtils::getClass($this->getSubject());
         }
 
@@ -1013,7 +1013,7 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
             if (count($this->getSubClasses()) > 0) {
                 $subject = $this->getSubject();
 
-                if ($subject) {
+                if ($subject && is_object($this->getSubject())) {
                     return ClassUtils::getClass($subject);
                 }
             }

+ 3 - 4
Form/Type/AdminType.php

@@ -16,6 +16,7 @@ use Symfony\Component\Form\FormBuilderInterface;
 use Symfony\Component\Form\FormInterface;
 use Symfony\Component\Form\FormView;
 
+use Symfony\Component\Form\ReversedTransformer;
 use Symfony\Component\OptionsResolver\Options;
 use Symfony\Component\OptionsResolver\OptionsResolverInterface;
 
@@ -28,15 +29,13 @@ class AdminType extends AbstractType
      */
     public function buildForm(FormBuilderInterface $builder, array $options)
     {
-        $admin = $this->getAdmin($options);
+        $admin = clone $this->getAdmin($options);
 
         if ($options['delete'] && $admin->isGranted('DELETE')) {
             $builder->add('_delete', 'checkbox', array('required' => false, 'mapped' => false, 'translation_domain' => $admin->getTranslationDomain()));
         }
 
-        if (!$admin->hasSubject()) {
-            $admin->setSubject($builder->getData());
-        }
+        $admin->setSubject($builder->getData());
 
         $admin->defineFormBuilder($builder);