ソースを参照

Add an option to set the label on a filter

Thomas Rabaix 13 年 前
コミット
fef8f04a86

+ 5 - 0
Filter/Filter.php

@@ -75,6 +75,11 @@ abstract class Filter implements FilterInterface
         return $this->getOption('field_options', array('required' => false));
         return $this->getOption('field_options', array('required' => false));
     }
     }
 
 
+    public function getLabel()
+    {
+        return $this->getOption('label', $this->getName());
+    }
+
     /**
     /**
      * @return string
      * @return string
      */
      */

+ 8 - 0
Filter/FilterInterface.php

@@ -32,6 +32,14 @@ interface FilterInterface
      */
      */
     function getName();
     function getName();
 
 
+    /**
+     * Returns the label name
+     *
+     * @abstract
+     * @return void
+     */
+    function getLabel();
+
     /**
     /**
      * @abstract
      * @abstract
      * @return array
      * @return array

+ 1 - 0
Filter/ORM/BooleanFilter.php

@@ -69,6 +69,7 @@ class BooleanFilter extends Filter
             'field_options' => $this->getFieldOptions(),
             'field_options' => $this->getFieldOptions(),
             'operator_type' => 'hidden',
             'operator_type' => 'hidden',
             'operator_options' => array(),
             'operator_options' => array(),
+            'label'         => $this->getLabel()
         ));
         ));
     }
     }
 }
 }

+ 1 - 0
Filter/ORM/CallbackFilter.php

@@ -60,6 +60,7 @@ class CallbackFilter extends Filter
             'field_options' => $this->getFieldOptions(),
             'field_options' => $this->getFieldOptions(),
             'operator_type' => $this->getOption('operator_type'),
             'operator_type' => $this->getOption('operator_type'),
             'operator_options' => $this->getOption('operator_options'),
             'operator_options' => $this->getOption('operator_options'),
+            'label'         => $this->getLabel()
         ));
         ));
     }
     }
 }
 }

+ 1 - 0
Filter/ORM/ChoiceFilter.php

@@ -84,6 +84,7 @@ class ChoiceFilter extends Filter
             'operator_type' => 'sonata_type_boolean',
             'operator_type' => 'sonata_type_boolean',
             'field_type'    => $this->getFieldType(),
             'field_type'    => $this->getFieldType(),
             'field_options' => $this->getFieldOptions(),
             'field_options' => $this->getFieldOptions(),
+            'label'         => $this->getLabel()
         ));
         ));
     }
     }
 }
 }

+ 1 - 0
Filter/ORM/ModelFilter.php

@@ -105,6 +105,7 @@ class ModelFilter extends Filter
             'field_options' => $this->getFieldOptions(),
             'field_options' => $this->getFieldOptions(),
             'operator_type' => $this->getOption('operator_type'),
             'operator_type' => $this->getOption('operator_type'),
             'operator_options' => $this->getOption('operator_options'),
             'operator_options' => $this->getOption('operator_options'),
+            'label'         => $this->getLabel()
         ));
         ));
     }
     }
 }
 }

+ 1 - 0
Filter/ORM/NumberFilter.php

@@ -71,6 +71,7 @@ class NumberFilter extends Filter
         return array('sonata_type_filter_number', array(
         return array('sonata_type_filter_number', array(
             'field_type'    => $this->getFieldType(),
             'field_type'    => $this->getFieldType(),
             'field_options' => $this->getFieldOptions(),
             'field_options' => $this->getFieldOptions(),
+            'label'         => $this->getLabel()
         ));
         ));
     }
     }
 }
 }

+ 1 - 0
Filter/ORM/StringFilter.php

@@ -82,6 +82,7 @@ class StringFilter extends Filter
         return array('sonata_type_filter_choice', array(
         return array('sonata_type_filter_choice', array(
             'field_type'    => $this->getFieldType(),
             'field_type'    => $this->getFieldType(),
             'field_options' => $this->getFieldOptions(),
             'field_options' => $this->getFieldOptions(),
+            'label'         => $this->getLabel()
         ));
         ));
     }
     }
 }
 }

+ 15 - 0
Resources/doc/reference/filter_field_definition.rst

@@ -66,6 +66,21 @@ Example
 Advanced usage
 Advanced usage
 --------------
 --------------
 
 
+Label
+^^^^^
+
+You can customize the label which appears on the main widget by using a ``label`` option.
+
+.. code-block:: php
+
+    <?php
+
+    ->add('tags', null, array('label' => 'les tags'), null, array('expanded' => true, 'multiple' => true)
+
+
+Callback
+^^^^^^^^
+
 To create a custom callback filter, two methods need to be implemented; one to
 To create a custom callback filter, two methods need to be implemented; one to
 define the field type and one to define how to use the field's value. In this
 define the field type and one to define how to use the field's value. In this
 example, ``getWithOpenCommentField`` and ``getWithOpenCommentFilter`` implement
 example, ``getWithOpenCommentField`` and ``getWithOpenCommentFilter`` implement