Przeglądaj źródła

add form field reorder

Gordon Franke 13 lat temu
rodzic
commit
c08a71ed94
2 zmienionych plików z 22 dodań i 0 usunięć
  1. 7 0
      Admin/Admin.php
  2. 15 0
      Form/FormMapper.php

+ 7 - 0
Admin/Admin.php

@@ -1290,6 +1290,13 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
         $this->formGroups = $formGroups;
         $this->formGroups = $formGroups;
     }
     }
 
 
+    public function reorderFormGroup($group, array $keys)
+    {
+        $formGroups = $this->getFormGroups();
+        $formGroups[$group]['fields'] = array_merge(array_flip($keys), $formGroups[$group]['fields']);
+        $this->setFormGroups($formGroups);
+    }
+
     public function getShowGroups()
     public function getShowGroups()
     {
     {
         return $this->showGroups;
         return $this->showGroups;

+ 15 - 0
Form/FormMapper.php

@@ -67,6 +67,21 @@ class FormMapper
         return $this;
         return $this;
     }
     }
 
 
+    /**
+     * @param array $keys field names
+     * @return \Sonata\AdminBundle\Form\FormMapper
+     */
+    public function reorder(array $keys)
+    {
+        if (!$this->currentGroup) {
+            $this->with($this->admin->getLabel());
+        }
+
+        $this->admin->reorderFormGroup($this->currentGroup, $keys);
+
+        return $this;
+    }
+
     /**
     /**
      * @param string $name
      * @param string $name
      * @param string $type
      * @param string $type