Parcourir la source

Merge pull request #1587 from tiagojsag/sonata_type_buttons

Added custom catalogue for sonata_type buttons
Thomas il y a 11 ans
Parent
commit
b924a33dc8

+ 3 - 1
Form/Type/AdminType.php

@@ -51,6 +51,7 @@ class AdminType extends AbstractType
         $view->vars['btn_add'] = $options['btn_add'];
         $view->vars['btn_list'] = $options['btn_list'];
         $view->vars['btn_delete'] = $options['btn_delete'];
+        $view->vars['btn_catalogue'] = $options['btn_catalogue'];
     }
 
     /**
@@ -65,7 +66,8 @@ class AdminType extends AbstractType
             'auto_initialize' => false,
             'btn_add'         => 'link_add',
             'btn_list'        => 'link_list',
-            'btn_delete'      => 'link_delete'
+            'btn_delete'      => 'link_delete',
+            'btn_catalogue'   => 'SonataAdminBundle'
         ));
     }
 

+ 2 - 0
Form/Type/CollectionType.php

@@ -44,6 +44,7 @@ class CollectionType extends AbstractType
     public function buildView(FormView $view, FormInterface $form, array $options)
     {
         $view->vars['btn_add'] = $options['btn_add'];
+        $view->vars['btn_catalogue'] = $options['btn_catalogue'];
     }
 
     /**
@@ -56,6 +57,7 @@ class CollectionType extends AbstractType
             'type'          => 'text',
             'type_options'  => array(),
             'btn_add'       => 'link_add',
+            'btn_catalogue' => 'SonataAdminBundle'
         ));
     }
 

+ 2 - 0
Form/Type/ModelType.php

@@ -55,6 +55,7 @@ class ModelType extends AbstractType
         $view->vars['btn_add'] = $options['btn_add'];
         $view->vars['btn_list'] = $options['btn_list'];
         $view->vars['btn_delete'] = $options['btn_delete'];
+        $view->vars['btn_catalogue'] = $options['btn_catalogue'];
     }
 
     /**
@@ -79,6 +80,7 @@ class ModelType extends AbstractType
             'btn_add'           => 'link_add',
             'btn_list'          => 'link_list',
             'btn_delete'        => 'link_delete',
+            'btn_catalogue'     => 'SonataAdminBundle',
             'choice_list'       => function (Options $options, $previousValue) {
                 if ($previousValue instanceof ChoiceListInterface && count($choices = $previousValue->getChoices())) {
                     return $choices;

+ 2 - 0
Form/Type/ModelTypeList.php

@@ -50,6 +50,7 @@ class ModelTypeList extends AbstractType
         $view->vars['btn_add'] = $options['btn_add'];
         $view->vars['btn_list'] = $options['btn_list'];
         $view->vars['btn_delete'] = $options['btn_delete'];
+        $view->vars['btn_catalogue'] = $options['btn_catalogue'];
     }
 
     /**
@@ -64,6 +65,7 @@ class ModelTypeList extends AbstractType
             'btn_add'           => 'link_add',
             'btn_list'          => 'link_list',
             'btn_delete'        => 'link_delete',
+            'btn_catalogue'     => 'SonataAdminBundle'
         ));
     }
 

+ 9 - 6
Resources/doc/reference/form_types.rst

@@ -80,10 +80,11 @@ class
   calculated from the linked Admin class. You usually should not need to set
   this manually.
 
-btn_add, btn_list and btn_delete:
+btn_add, btn_list, btn_delete and btn_catalogue:
   The labels on the ``add``, ``list`` and ``delete`` buttons can be customized
   with these parameters. Setting any of them to ``false`` will hide the 
-  corresponding button.
+  corresponding button. You can also specify a custom translation catalogue
+  for these labels, which defaults to ``SonataAdminBundle``.
 
 sonata_type_admin
 ^^^^^^^^^^^^^^^^^
@@ -149,10 +150,11 @@ delete
   defaults to true and indicates that a 'delete' checkbox should be shown allowing
   the user to delete the linked object.
 
-btn_add, btn_list and btn_delete:
+btn_add, btn_list, btn_delete and btn_catalogue:
   The labels on the ``add``, ``list`` and ``delete`` buttons can be customized
   with these parameters. Setting any of them to ``false`` will hide the 
-  corresponding button.
+  corresponding button. You can also specify a custom translation catalogue
+  for these labels, which defaults to ``SonataAdminBundle``.
 
 
 sonata_type_collection
@@ -184,10 +186,11 @@ to the underlying forms.
     
 The available options (which can be passed as a third parameter to ``FormMapper::add()``) are:
 
-btn_add:
+btn_add and btn_catalogue:
   The label on the ``add`` button can be customized
   with this parameters. Setting it to ``false`` will hide the 
-  corresponding button.
+  corresponding button. You can also specify a custom translation catalogue
+  for this label, which defaults to ``SonataAdminBundle``.
 
 **TIP**: A jQuery event is fired after a row has been added (``sonata-collection-item-added``)
 or deleted (``sonata-collection-item-deleted``). You can bind to these events to trigger custom

+ 1 - 0
Tests/Form/Type/AdminTypeTest.php

@@ -32,5 +32,6 @@ class AdminTypeTest extends TypeTestCase
         $this->assertEquals('link_add', $options['btn_add']);
         $this->assertEquals('link_list', $options['btn_list']);
         $this->assertEquals('link_delete', $options['btn_delete']);
+        $this->assertEquals('SonataAdminBundle', $options['btn_catalogue']);
     }
 }

+ 1 - 0
Tests/Form/Type/CollectionTypeTest.php

@@ -31,5 +31,6 @@ class CollectionTypeTest extends TypeTestCase
         $this->assertEquals('text', $options['type']);
         $this->assertEquals(0, count($options['type_options']));
         $this->assertEquals('link_add', $options['btn_add']);
+        $this->assertEquals('SonataAdminBundle', $options['btn_catalogue']);
     }
 }

+ 1 - 0
Tests/Form/Type/ModelTypeListTest.php

@@ -32,5 +32,6 @@ class ModelTypeListTest extends TypeTestCase
         $this->assertEquals('link_add', $options['btn_add']);
         $this->assertEquals('link_list', $options['btn_list']);
         $this->assertEquals('link_delete', $options['btn_delete']);
+        $this->assertEquals('SonataAdminBundle', $options['btn_catalogue']);
     }
 }

+ 1 - 0
Tests/Form/Type/ModelTypeTest.php

@@ -41,6 +41,7 @@ class ModelTypeTest extends TypeTestCase
         $this->assertEquals('link_add', $options['btn_add']);
         $this->assertEquals('link_list', $options['btn_list']);
         $this->assertEquals('link_delete', $options['btn_delete']);
+        $this->assertEquals('SonataAdminBundle', $options['btn_catalogue']);
         $this->assertInstanceOf('Sonata\AdminBundle\Form\ChoiceList\ModelChoiceList', $options['choice_list']);
     }
 }