Browse Source

fix set up header label in list mapper (#4602)

Adam 7 years ago
parent
commit
1b1d4b47d9
2 changed files with 12 additions and 1 deletions
  1. 6 1
      Datagrid/ListMapper.php
  2. 6 0
      Tests/Datagrid/ListMapperTest.php

+ 6 - 1
Datagrid/ListMapper.php

@@ -117,11 +117,16 @@ class ListMapper extends BaseMapper
             );
         }
 
-        if ($fieldDescription->getLabel() !== false) {
+        if ($fieldDescription->getLabel() === null) {
             $fieldDescription->setOption(
                 'label',
                 $this->admin->getLabelTranslatorStrategy()->getLabel($fieldDescription->getName(), 'list', 'label')
             );
+        } elseif ($fieldDescription->getLabel() !== false) {
+            $fieldDescription->setOption(
+                'label',
+                $this->admin->getLabelTranslatorStrategy()->getLabel($fieldDescription->getLabel(), 'list', 'label')
+            );
         }
 
         // add the field with the FormBuilder

+ 6 - 0
Tests/Datagrid/ListMapperTest.php

@@ -110,14 +110,20 @@ class ListMapperTest extends PHPUnit_Framework_TestCase
     public function testAdd()
     {
         $this->listMapper->add('fooName');
+        $this->listMapper->add('fooNameLabelBar', null, array('label' => 'fooBar'));
+        $this->listMapper->add('fooNameLabelFalse', null, array('label' => false));
 
         $this->assertTrue($this->listMapper->has('fooName'));
 
         $fieldDescription = $this->listMapper->get('fooName');
+        $fieldLabelBar = $this->listMapper->get('fooNameLabelBar');
+        $fieldLabelFalse = $this->listMapper->get('fooNameLabelFalse');
 
         $this->assertInstanceOf('Sonata\AdminBundle\Admin\FieldDescriptionInterface', $fieldDescription);
         $this->assertSame('fooName', $fieldDescription->getName());
         $this->assertSame('fooName', $fieldDescription->getOption('label'));
+        $this->assertSame('fooBar', $fieldLabelBar->getOption('label'));
+        $this->assertFalse($fieldLabelFalse->getOption('label'));
     }
 
     /**