Bladeren bron

Merge pull request #1857 from marekkalnik/benoitpointet-batch_action_label

Benoitpointet batch action label
Marek Kalnik 11 jaren geleden
bovenliggende
commit
29ca1a7bf1

+ 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 = '');
 }

+ 3 - 0
Controller/CRUDController.php

@@ -440,10 +440,13 @@ class CRUDController extends Controller
         $askConfirmation = isset($batchActions[$action]['ask_confirmation']) ? $batchActions[$action]['ask_confirmation'] : true;
 
         if ($askConfirmation && $confirmation != 'ok') {
+            $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' => $actionLabel,
                 'datagrid'   => $datagrid,
                 'form'       => $formView,
                 'data'       => $data,

+ 1 - 1
Resources/translations/SonataAdminBundle.de.xliff

@@ -188,7 +188,7 @@
             </trans-unit>
             <trans-unit id="title_batch_confirmation">
                 <source>title_batch_confirmation</source>
-                <target>Stapel-Aktion bestätigen</target>
+                <target>Stapel-Aktion '%action%' bestätigen</target>
             </trans-unit>
             <trans-unit id="message_batch_confirmation">
                 <source>message_batch_confirmation</source>

+ 1 - 1
Resources/translations/SonataAdminBundle.en.xliff

@@ -188,7 +188,7 @@
             </trans-unit>
             <trans-unit id="title_batch_confirmation">
                 <source>title_batch_confirmation</source>
-                <target>Confirm batch action</target>
+                <target>Confirm batch action '%action%'</target>
             </trans-unit>
             <trans-unit id="message_batch_confirmation">
                 <source>message_batch_confirmation</source>

+ 1 - 1
Resources/translations/SonataAdminBundle.fr.xliff

@@ -188,7 +188,7 @@
             </trans-unit>
             <trans-unit id="title_batch_confirmation">
                 <source>title_batch_confirmation</source>
-                <target>Confirmation d'un traitement par lots</target>
+                <target>Confirmation d'un traitement par lots: '%action%'</target>
             </trans-unit>
             <trans-unit id="message_batch_confirmation">
                 <source>message_batch_confirmation</source>

+ 1 - 1
Resources/views/CRUD/batch_confirmation.html.twig

@@ -22,7 +22,7 @@ file that was distributed with this source code.
 
 {% block content %}
     <div class="sonata-ba-delete">
-        <h1>{{ 'title_batch_confirmation'|trans({}, 'SonataAdminBundle') }}</h1>
+        <h1>{% trans with {'%action%': action_label} from 'SonataAdminBundle' %}title_batch_confirmation{% endtrans %}</h1>
 
         {% if data.all_elements %}
             {{ 'message_batch_all_confirmation'|trans({}, 'SonataAdminBundle') }}

+ 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');