Browse Source

Added configureBatchActions method to AbstractAdmin (#3853)

Christian Gripp 9 năm trước cách đây
mục cha
commit
83c9dbb531
3 tập tin đã thay đổi với 49 bổ sung0 xóa
  1. 14 0
      Admin/AbstractAdmin.php
  2. 21 0
      Tests/Admin/AdminTest.php
  3. 14 0
      Tests/Fixtures/Admin/PostAdmin.php

+ 14 - 0
Admin/AbstractAdmin.php

@@ -1054,6 +1054,8 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface
             );
         }
 
+        $actions = $this->configureBatchActions($actions);
+
         foreach ($this->getExtensions() as $extension) {
             // TODO: remove method check in next major release
             if (method_exists($extension, 'configureBatchActions')) {
@@ -2877,6 +2879,18 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface
     {
     }
 
+     /**
+      * Allows you to customize batch actions.
+      *
+      * @param array $actions List of actions
+      *
+      * @return array
+      */
+     protected function configureBatchActions($actions)
+     {
+         return $actions;
+     }
+
     /**
      * DEPRECATED: Use configureTabMenu instead.
      *

+ 21 - 0
Tests/Admin/AdminTest.php

@@ -1789,6 +1789,27 @@ class AdminTest extends \PHPUnit_Framework_TestCase
         $this->assertSame($expected, $admin->getActionButtons('list', null));
     }
 
+    /**
+     * @covers Sonata\AdminBundle\Admin\AbstractAdmin::configureBatchActions
+     */
+    public function getBatchActions()
+    {
+        $expected = array(
+            'action' => array(
+                'label' => 'action_delete',
+                'translation_domain' => 'SonataAdminBundle',
+                'ask_confirmation' => true, // by default always true
+            ),
+            'foo' => array(
+                'label' => 'action_foo',
+            ),
+        );
+
+        $modelAdmin = new PostAdmin('sonata.post.admin.model', 'Application\Sonata\FooBundle\Entity\Model', 'SonataFooBundle:ModelAdmin');
+
+        $this->assertSame($expected, $modelAdmin->getBatchActions());
+    }
+
     /**
      * @covers Sonata\AdminBundle\Admin\AbstractAdmin::getDashboardActions
      * @dataProvider provideGetBaseRouteName

+ 14 - 0
Tests/Fixtures/Admin/PostAdmin.php

@@ -26,4 +26,18 @@ class PostAdmin extends AbstractAdmin
 
         return parent::getClassMetaData();
     }
+
+    /**
+     * @param array $actions
+     *
+     * @return array
+     */
+    protected function configureBatchActions($actions)
+    {
+        $actions['foo'] = array(
+            'label' => 'action_foo',
+        );
+
+        return $actions;
+    }
 }