Просмотр исходного кода

Added the ability to remove the label of a show field (#4398)

Romain Sanchez 8 лет назад
Родитель
Сommit
8165fcedcd
3 измененных файлов с 17 добавлено и 1 удалено
  1. 9 0
      Resources/doc/reference/action_show.rst
  2. 1 1
      Show/ShowMapper.php
  3. 7 0
      Tests/Show/ShowMapperTest.php

+ 9 - 0
Resources/doc/reference/action_show.rst

@@ -135,6 +135,15 @@ The following is a working example of a ShowAction
         }
     }
 
+.. tip::
+    To customize the displayed label of a show field you can use the ``label`` option:
+
+    .. code-block:: php
+    
+        $showMapper->add('name', null, array('label' => 'UserName'));
+
+    Setting this option to ``false`` will make the label empty.
+
 Setting up a custom show template (very useful)
 ===============================================
 

+ 1 - 1
Show/ShowMapper.php

@@ -73,7 +73,7 @@ class ShowMapper extends BaseGroupedMapper
             throw new \RuntimeException('invalid state');
         }
 
-        if (!$fieldDescription->getLabel()) {
+        if (!$fieldDescription->getLabel() && false !== $fieldDescription->getOption('label')) {
             $fieldDescription->setOption('label', $this->admin->getLabelTranslatorStrategy()->getLabel($fieldDescription->getName(), 'show', 'label'));
         }
 

+ 7 - 0
Tests/Show/ShowMapperTest.php

@@ -435,6 +435,13 @@ class ShowMapperTest extends PHPUnit_Framework_TestCase
         $this->assertSame(array(), $this->admin->getShowTabs());
     }
 
+    public function testEmptyFieldLabel()
+    {
+        $this->showMapper->add('foo', null, array('label' => false));
+
+        $this->assertFalse($this->showMapper->get('foo')->getOption('label'));
+    }
+
     private function cleanShowMapper()
     {
         $this->showBuilder = $this->getMockForAbstractClass('Sonata\AdminBundle\Builder\ShowBuilderInterface');