Forráskód Böngészése

- Add new method to admin extension to add persistent parameters + alter object instance - Add AbstractTranslatableAdminExtension

Nicolas Bastien 11 éve
szülő
commit
49f48f3c51
3 módosított fájl, 41 hozzáadás és 2 törlés
  1. 12 2
      Admin/Admin.php
  2. 12 0
      Admin/AdminExtension.php
  3. 17 0
      Admin/AdminExtensionInterface.php

+ 12 - 2
Admin/Admin.php

@@ -1321,7 +1321,12 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      */
     public function getObject($id)
     {
-        return $this->getModelManager()->find($this->getClass(), $id);
+        $object = $this->getModelManager()->find($this->getClass(), $id);
+        foreach ($this->getExtensions() as $extension) {
+            $extension->alterObject($this, $object);
+        }
+
+        return $object;
     }
 
     /**
@@ -1916,7 +1921,12 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
      */
     public function getPersistentParameters()
     {
-        return array();
+        $parameters = array();
+        foreach ($this->getExtensions() as $extension) {
+            $parameters = array_merge($parameters, $extension->getPersistentParameters($this));
+        }
+
+        return $parameters;
     }
 
     /**

+ 12 - 0
Admin/AdminExtension.php

@@ -77,6 +77,18 @@ abstract class AdminExtension implements AdminExtensionInterface
     public function alterNewInstance(AdminInterface $admin, $object)
     {}
 
+    /**
+     * {@inheritdoc}
+     */
+    public function alterObject(AdminInterface $admin, $object)
+    {}
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getPersistentParameters(AdminInterface $admin)
+    {}
+
     /**
      * {@inheritdoc}
      */

+ 17 - 0
Admin/AdminExtensionInterface.php

@@ -83,6 +83,23 @@ interface AdminExtensionInterface
      */
     public function alterNewInstance(AdminInterface $admin, $object);
 
+    /**
+     * Get a chance to modify object instance
+     *
+     * @param  AdminInterface $admin
+     * @param  $object
+     * @return mixed
+     */
+    public function alterObject(AdminInterface $admin, $object);
+
+    /**
+     * Get a chance to add persistent parameters
+     *
+     * @param  AdminInterface $admin
+     * @return array
+     */
+    public function getPersistentParameters(AdminInterface $admin);
+
     /**
      * @param AdminInterface $admin
      * @param mixed          $object