Browse Source

Use FQCN instead of form alias (#4541)

This fixes a deprecation warning.
Koen Verheyen 7 năm trước cách đây
mục cha
commit
bf82cf6302

+ 11 - 4
Admin/Extension/LockExtension.php

@@ -57,10 +57,17 @@ class LockExtension extends AbstractAdminExtension
                 return;
             }
 
-            $form->add($fieldName, 'hidden', array(
-                'mapped' => false,
-                'data' => $lockVersion,
-            ));
+            $form->add(
+                $fieldName,
+                // NEXT_MAJOR: remove the check and add the FQCN
+                method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')
+                    ? 'Symfony\Component\Form\Extension\Core\Type\HiddenType'
+                    : 'hidden',
+                array(
+                    'mapped' => false,
+                    'data' => $lockVersion,
+                )
+            );
         });
     }
 

+ 9 - 1
Tests/Admin/Extension/LockExtensionTest.php

@@ -70,7 +70,15 @@ class LockExtensionTest extends \PHPUnit_Framework_TestCase
         $event = new FormEvent($form->reveal(), array());
 
         $this->modelManager->getLockVersion(array())->willReturn(1);
-        $form->add('_lock_version', 'hidden', array('mapped' => false, 'data' => 1))->shouldBeCalled();
+
+        $form->add(
+            '_lock_version',
+            // NEXT_MAJOR: remove the check and add the FQCN
+            method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')
+                ? 'Symfony\Component\Form\Extension\Core\Type\HiddenType'
+                : 'hidden',
+            array('mapped' => false, 'data' => 1)
+        )->shouldBeCalled();
 
         $this->lockExtension->configureFormFields($formMapper);
         $this->eventDispatcher->dispatch(FormEvents::PRE_SET_DATA, $event);