Source of file StateDropdownField.php
Size: 3,666 Bytes - Last Modified: 2021-12-24T06:45:42+00:00
/var/www/docs.ssmods.com/process/src/src/Form/StateDropdownField.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 | <?php namespace Dynamic\AdditionalFormFields\Form; use SilverStripe\Forms\DropdownField; /** * A simple extension to dropdown field, pre-configured to list states. */ class StateDropdownField extends DropdownField { /** * Should we default the dropdown to the region determined from the user's locale? * * @var bool */ //private static $default_to_locale = true; public static $stateSource = array( 'AL' => 'Alabama', 'AK' => 'Alaska', 'AZ' => 'Arizona', 'AR' => 'Arkansas', 'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware', 'DC' => 'District Of Columbia', 'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho', 'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas', 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine', 'MD' => 'Maryland', 'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi', 'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada', 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York', 'NC' => 'North Carolina', 'ND' => 'North Dakota', 'OH' => 'Ohio', 'OK' => 'Oklahoma', 'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', 'SC' => 'South Carolina', 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah', 'VT' => 'Vermont', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia', 'WI' => 'Wisconsin', 'WY' => 'Wyoming', '-' => '-----', 'AB' => 'Alberta', 'BC' => 'British Columbia', 'MB' => 'Manitoba', 'NB' => 'New Brunswick', 'NL' => 'Newfoundland and Labrador', 'NS' => 'Nova Scotia', 'ON' => 'Ontario', 'PE' => 'Prince Edward Island', 'QC' => 'Quebec', 'SK' => 'Saskatchewan', ); /** * The region code to default to if default_to_locale is set to false, or we can't determine a region from a locale. * * @var string */ //private static $default_state = 'WI'; protected $extraClasses = array('dropdown'); /** * Get the locale of the Member, or if we're not logged in or don't have a locale, use the default one. * * @return string */ /*protected function locale() { if (($member = Member::currentUser()) && $member->Locale) return $member->Locale; return i18n::get_locale(); }*/ /** * StateDropdownField constructor. * * @param string $name The field name * @param string $title The field title * @param array|\ArrayAccess $source A map of the dropdown items * @param mixed $value The current value */ public function __construct($name, $title = null, $source = null, $value = '') { if (!is_array($source)) { // Get a list of countries from Zend $source = self::$stateSource; } parent::__construct($name, $title, $source, $value); } public function Field($properties = array()) { $source = $this->getSource(); if (!$this->value || !isset($source[$this->value])) { $this->value = $this->config()->get('default_state'); } return parent::Field(); } } |