Przeglądaj źródła

add show field reorder

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

+ 7 - 0
Admin/Admin.php

@@ -1307,6 +1307,13 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
         $this->showGroups = $showGroups;
     }
 
+    public function reorderShowGroup($group, array $keys)
+    {
+        $showGroups = $this->getShowGroups();
+        $showGroups[$group]['fields'] = array_merge(array_flip($keys), $showGroups[$group]['fields']);
+        $this->setShowGroups($showGroups);
+    }
+
     /**
      * {@inheritdoc}
      */

+ 15 - 0
Show/ShowMapper.php

@@ -115,6 +115,21 @@ class ShowMapper
         return $this;
     }
 
+    /**
+     * @param array $keys field names
+     * @return \Sonata\AdminBundle\Show\ShowMapper
+     */
+    public function reorder(array $keys)
+    {
+        if (!$this->currentGroup) {
+            $this->with($this->admin->getLabel());
+        }
+
+        $this->admin->reorderShowGroup($this->currentGroup, $keys);
+
+        return $this;
+    }
+
     /**
      * @param string $name
      * @param array $options