Browse Source

Add method for getting labels using current translationStrategy

Marek Kalnik 11 years ago
parent
commit
db2e9355a6

+ 8 - 0
Admin/Admin.php

@@ -2134,6 +2134,14 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
         return $this->translator;
     }
 
+    /**
+     * {@inheritdoc}
+     */
+    public function getTranslationLabel($label, $context = '', $type = '')
+    {
+        return $this->getLabelTranslatorStrategy()->getLabel($label, $context, $type);
+    }
+
     /**
      * {@inheritdoc}
      */

+ 11 - 0
Admin/AdminInterface.php

@@ -931,4 +931,15 @@ interface AdminInterface
      * @return bool
      */
     public function getCurrentChild();
+
+    /**
+     * Get translation label using the current TranslationStrategy.
+     *
+     * @param string $label
+     * @param string $context
+     * @param string $type
+     *
+     * @return string
+     */
+    public function getTranslationLabel($label, $context = '', $type = '');
 }

+ 2 - 2
Controller/CRUDController.php

@@ -440,13 +440,13 @@ class CRUDController extends Controller
         $askConfirmation = isset($batchActions[$action]['ask_confirmation']) ? $batchActions[$action]['ask_confirmation'] : true;
 
         if ($askConfirmation && $confirmation != 'ok') {
-            $label = $this->admin->trans($this->admin->getLabelTranslatorStrategy()->getLabel($action, 'action'));
+            $actionLabel = $this->admin->trans($this->admin->getTranslationLabel($action, 'action'));
 
             $formView = $datagrid->getForm()->createView();
 
             return $this->render($this->admin->getTemplate('batch_confirmation'), array(
                 'action'     => 'list',
-                'action_label' => $label,
+                'action_label' => $actionLabel,
                 'datagrid'   => $datagrid,
                 'form'       => $formView,
                 'data'       => $data,

+ 5 - 0
Tests/Controller/CRUDControllerTest.php

@@ -2157,6 +2157,11 @@ class CRUDControllerTest extends \PHPUnit_Framework_TestCase
             ->method('getBatchActions')
             ->will($this->returnValue($batchActions));
 
+        $this->admin->expects($this->once())
+            ->method('getTranslationLabel')
+            ->with($this->equalTo('delete'), $this->equalTo('action'))
+            ->will($this->returnValue('delete_action'));
+
         $data = array('action'=>'delete', 'idx'=>array('123', '456'), 'all_elements'=>false);
 
         $this->request->setMethod('POST');