ソースを参照

Start usage of Label Translator strategy - BC

Thomas Rabaix 13 年 前
コミット
d954c834e3

+ 4 - 0
Admin/Admin.php

@@ -863,6 +863,10 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
         return $this->routes->get($name);
     }
 
+    /**
+     * @param $name
+     * @return bool
+     */
     public function hasRoute($name)
     {
         $this->buildRoutes();

+ 1 - 1
Admin/BaseFieldDescription.php

@@ -472,6 +472,6 @@ abstract class BaseFieldDescription implements FieldDescriptionInterface
      */
     public function getLabel()
     {
-        return $this->getOption('label', $this->getOption('name', $this->getName()));
+        return $this->getOption('label');
     }
 }

+ 4 - 0
Datagrid/ListMapper.php

@@ -65,6 +65,10 @@ class ListMapper
             throw new \RuntimeException('invalid state');
         }
 
+        if (!$fieldDescription->getLabel()) {
+            $fieldDescription->setOption('label', $this->admin->getLabelTranslatorStrategy()->getLabel($fieldDescription->getName()));
+        }
+
         // add the field with the FormBuilder
         $this->listBuilder->addField($this->list, $type, $fieldDescription, $this->admin);
 

+ 5 - 0
DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php

@@ -155,6 +155,10 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
             $definition->addMethodCall('setRouteBuilder', array(new Reference('sonata.admin.route.path_info')));
         }
 
+        if (!$definition->hasMethodCall('setLabelTranslatorStrategy')) {
+            $definition->addMethodCall('setLabelTranslatorStrategy', array(new Reference('sonata.admin.label.strategy.form_component')));
+        }
+
         if (isset($service['label'])) {
             $label = $service['label'];
         } elseif (isset($attributes['label'])) {
@@ -162,6 +166,7 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
         } else {
             $label = '-';
         }
+
         $definition->addMethodCall('setLabel', array($label));
 
         $definition->addMethodCall('configure');

+ 1 - 0
DependencyInjection/SonataAdminExtension.php

@@ -73,6 +73,7 @@ class SonataAdminExtension extends Extension
          * This is a work in progress, so for now it is hardcoded
          */
         $classes = array(
+            'email'    => 'sonata-medium',
             'textarea' => 'sonata-medium',
             'text'     => 'sonata-medium',
             'choice'   => 'sonata-medium',

+ 1 - 1
Filter/Filter.php

@@ -89,7 +89,7 @@ abstract class Filter implements FilterInterface
      */
     public function getLabel()
     {
-        return $this->getOption('label', $this->getName());
+        return $this->getOption('label');
     }
 
     /**

+ 6 - 2
Form/FormMapper.php

@@ -96,13 +96,17 @@ class FormMapper
 
         $this->formContractor->fixFieldDescription($this->admin, $fieldDescription, $fieldDescriptionOptions);
 
-        $options = array_merge($options, $this->formContractor->getDefaultOptions($type, $fieldDescription));
-
         $this->admin->addFormFieldDescription($name instanceof FormBuilder ? $name->getName() : $name, $fieldDescription);
 
         if ($name instanceof FormBuilder) {
             $this->formBuilder->add($name);
         } else {
+            $options = array_merge($options, $this->formContractor->getDefaultOptions($type, $fieldDescription));
+
+            if (!isset($options['label'])) {
+                $options['label'] = $this->admin->getLabelTranslatorStrategy()->getLabel($fieldDescription->getName());
+            }
+
             $this->formBuilder->add($name, $type, $options);
         }
 

+ 1 - 1
Resources/config/core.xml

@@ -44,7 +44,7 @@
         <service id="sonata.admin.label.strategy.native" class="Sonata\AdminBundle\Translator\NativeLabelTranslatorStrategy" />
         <service id="sonata.admin.label.strategy.noop" class="Sonata\AdminBundle\Translator\NoopLabelTranslatorStrategy" />
         <service id="sonata.admin.label.strategy.underscore" class="Sonata\AdminBundle\Translator\UnderscoreLabelTranslatorStrategy" />
-        <service id="sonata.admin.label.strategy.form_component" class="Sonata\AdminBundle\Translator\UnderscoreLabelTranslatorStrategy" />
+        <service id="sonata.admin.label.strategy.form_component" class="Sonata\AdminBundle\Translator\FormLabelTranslatorStrategy" />
 
     </services>
 </container>

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

@@ -151,7 +151,7 @@ file that was distributed with this source code.
                                 <table>
                                     {% for filter in admin.datagrid.filters %}
                                         <tr id="filter_{{ filter.name }}_row">
-                                            <td class="filter-title">{{ admin.trans(filter.name) }}</td>
+                                            <td class="filter-title">{{ admin.trans(filter.label) }}</td>
                                             <td class="filter-type">{{ form_widget(form.getChild(filter.name).getChild('type')) }}</td>
                                             <td class="filter-value">{{ form_widget(form.getChild(filter.name).getChild('value')) }}</td>
                                         </tr>