فهرست منبع

[Form] Refactored CountryField, LanguageField, LocaleField and BirthdayField to FormFactory

Bernhard Schussek 14 سال پیش
والد
کامیت
af8a093b00
1فایلهای تغییر یافته به همراه36 افزوده شده و 0 حذف شده
  1. 36 0
      src/Symfony/Component/Form/FormFactory.php

+ 36 - 0
src/Symfony/Component/Form/FormFactory.php

@@ -163,6 +163,33 @@ class FormFactory
         return $this->getChoiceFieldForList($key, $choiceList, $options);
     }
 
+    public function getCountryField($key, array $options = array())
+    {
+        $options = array_merge(array(
+            'choices' => Locale::getDisplayCountries(\Locale::getDefault()),
+        ), $options);
+
+        return $this->getChoiceField($key, $options);
+    }
+
+    public function getLanguageField($key, array $options = array())
+    {
+        $options = array_merge(array(
+            'choices' => Locale::getDisplayLanguages(\Locale::getDefault()),
+        ), $options);
+
+        return $this->getChoiceField($key, $options);
+    }
+
+    public function getLocaleField($key, array $options = array())
+    {
+        $options = array_merge(array(
+            'choices' => Locale::getDisplayLocales(\Locale::getDefault()),
+        ), $options);
+
+        return $this->getChoiceField($key, $options);
+    }
+
     protected function getDayField($key, array $options = array())
     {
         $options = array_merge(array(
@@ -332,6 +359,15 @@ class FormFactory
         return $field;
     }
 
+    public function getBirthdayField($key, array $options = array())
+    {
+        $options = array_merge(array(
+            'years' => range($currentYear-120, $currentYear),
+        ), $options);
+
+        return $this->getDateField($key, $options);
+    }
+
     public function getTimeField($key, array $options = array())
     {
         $options = array_merge(array(