瀏覽代碼

add form field reorder

Gordon Franke 13 年之前
父節點
當前提交
c08a71ed94
共有 2 個文件被更改,包括 22 次插入0 次删除
  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;
     }
 
+    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()
     {
         return $this->showGroups;

+ 15 - 0
Form/FormMapper.php

@@ -67,6 +67,21 @@ class FormMapper
         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 $type