Bläddra i källkod

Moved translation of batch action_label to template (#4071)

Christian Gripp 8 år sedan
förälder
incheckning
d487ed1a64

+ 5 - 2
Controller/CRUDController.php

@@ -417,14 +417,17 @@ class CRUDController extends Controller
             true;
             true;
 
 
         if ($askConfirmation && $confirmation != 'ok') {
         if ($askConfirmation && $confirmation != 'ok') {
-            $translationDomain = $batchActions[$action]['translation_domain'] ?: $this->admin->getTranslationDomain();
-            $actionLabel = $this->admin->trans($batchActions[$action]['label'], array(), $translationDomain);
+            $actionLabel = $batchActions[$action]['label'];
+            $batchTranslationDomain = isset($batchActions[$action]['translation_domain']) ?
+                $batchActions[$action]['translation_domain'] :
+                $this->admin->getTranslationDomain();
 
 
             $formView = $datagrid->getForm()->createView();
             $formView = $datagrid->getForm()->createView();
 
 
             return $this->render($this->admin->getTemplate('batch_confirmation'), array(
             return $this->render($this->admin->getTemplate('batch_confirmation'), array(
                 'action' => 'list',
                 'action' => 'list',
                 'action_label' => $actionLabel,
                 'action_label' => $actionLabel,
+                'batch_translation_domain' => $batchTranslationDomain,
                 'datagrid' => $datagrid,
                 'datagrid' => $datagrid,
                 'form' => $formView,
                 'form' => $formView,
                 'data' => $data,
                 'data' => $data,

+ 3 - 0
Resources/views/CRUD/batch_confirmation.html.twig

@@ -21,6 +21,9 @@ file that was distributed with this source code.
     <div class="sonata-ba-delete">
     <div class="sonata-ba-delete">
         <div class="box box-danger">
         <div class="box box-danger">
             <div class="box-header">
             <div class="box-header">
+                {% if batch_translation_domain is not same as(false) %}
+                    {% set action_label = action_label|trans({}, batch_translation_domain) %}
+                {% endif %}
                 <h4 class="box-title">{% trans with {'%action%': action_label} from 'SonataAdminBundle' %}title_batch_confirmation{% endtrans %}</h4>
                 <h4 class="box-title">{% trans with {'%action%': action_label} from 'SonataAdminBundle' %}title_batch_confirmation{% endtrans %}</h4>
             </div>
             </div>
             <div class="box-body">
             <div class="box-body">

+ 0 - 5
Tests/Controller/CRUDControllerTest.php

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