'select', '#title' => $title ? $title : t('countries'), '#default_value' => $default_value, '#options' => $options, '#description' => $description, ); } /** * returns a form-structure filled with US states, usefull in a select. * @param $title, the title of the form. Defaults to "coutries" (translated). If provided, it will not be translated * @param $default_value, the selected state. * @param $required, whether or not a "none" string should be included in the options. * @param $description, optionally provide a description. Is not translated. */ function states_select_for_form($title = '', $default_value = NULL, $required = FALSE, $description = '') { if ($required) { $options = _helpers_data_us_states_array(); } else { $options = add_none_to_options(_helpers_data_us_states_array()); } return array( '#type' => 'select', '#title' => $title ? $title : t('states'), '#default_value' => $default_value, '#options' => $options, '#description' => $description, ); } /** * This would be a very nice function to have in core * * @param string $variable_name * the name of the variable that is to be bound to a vocabulary * @param bool $multiple * whether or not multiple vocabularies should be bound to this vocabulary * @return array * a form array suitable for use in hook_settings */ function taxonomy_vocabulary_select($variable_name, $multiple = FALSE) { $form[$variable_name] = array( '#title' => t('Vocabularies associated with %variable', array('%variable' => $variable_name)), '#default_value' => variable_get($variable_name, array()), '#description' => t('These vocabularies will be bound to the variable %variable. You can get this list of vocabulary ids later by using variable_get("%variable", array());.', array('%variable' => $variable_name, '%variable' => $variable_name)), ); $form[$variable_name]['#type'] = $multiple ? 'checkboxes' : 'radios'; $options = array(); foreach(taxonomy_get_vocabularies() as $vid => $vocabulary) { $options[$vid] = $vocabulary->name; } $form[$variable_name]['#options'] = $options; return $form; } /** * Global and general functions * @param $options the options that you want to append "None" to. * @param $none_string optionally provide a string that will be the "none". If you provide this, it will not be translated and not passed trough the theme layer. */ function add_none_to_options($options, $none_string = NULL) { if ($none_string) { return array('' => $none_string) + $options; } else { return array('' => theme('none_option')) + $options; } } /** * Helper helpers. Private functions that are used internally */ /** * Returns a list of countries. * TODO make this a proper associative array with the official country code as key. */ function _helpers_data_countries_array($translated = TRUE) { $countries = array('Afghanistan' => 'Afghanistan', 'Albania' => 'Albania', 'Algeria' => 'Algeria', 'American Samoa' => 'American Samoa', 'Andorra' => 'Andorra', 'Angola' => 'Angola', 'Anguilla' => 'Anguilla', 'Antarctica' => 'Antarctica', 'Antigua And Barbuda' => 'Antigua And Barbuda', 'Argentina' => 'Argentina', 'Armenia' => 'Armenia', 'Aruba' => 'Aruba', 'Australia' => 'Australia', 'Austria' => 'Austria', 'Azerbaijan' => 'Azerbaijan', 'Bahamas' => 'Bahamas', 'Bahrain' => 'Bahrain', 'Bangladesh' => 'Bangladesh', 'Barbados' => 'Barbados', 'Belarus' => 'Belarus', 'Belgium' => 'Belgium', 'Belize' => 'Belize', 'Benin' => 'Benin', 'Bermuda' => 'Bermuda', 'Bhutan' => 'Bhutan', 'Bolivia' => 'Bolivia', 'Bosnia and Herzegowina' => 'Bosnia and Herzegowina', 'Botswana' => 'Botswana', 'Bouvet Island' => 'Bouvet Island', 'Brazil' => 'Brazil', 'British Indian Ocean Territory' => 'British Indian Ocean Territory', 'Brunei Darussalam' => 'Brunei Darussalam', 'Bulgaria' => 'Bulgaria', 'Burkina Faso' => 'Burkina Faso', 'Burma' => 'Burma', 'Burundi' => 'Burundi', 'Cambodia' => 'Cambodia', 'Cameroon' => 'Cameroon', 'Canada' => 'Canada', 'Cape Verde' => 'Cape Verde', 'Cayman Islands' => 'Cayman Islands', 'Central African Republic' => 'Central African Republic', 'Chad' => 'Chad', 'Chile' => 'Chile', 'China' => 'China', 'Christmas Island' => 'Christmas Island', 'Cocos (Keeling) Islands' => 'Cocos (Keeling) Islands', 'Colombia' => 'Colombia', 'Comoros' => 'Comoros', 'Congo' => 'Congo', 'Congo, the Democratic Republic of the', 'Cook Islands' => 'Cook Islands', 'Costa Rica' => 'Costa Rica', 'Cote d\'Ivoire' => 'Cote d\'Ivoire', 'Croatia' => 'Croatia', 'Cuba' => 'Cuba', 'Cyprus' => 'Cyprus', 'Czech Republic' => 'Czech Republic', 'Denmark' => 'Denmark', 'Djibouti' => 'Djibouti', 'Dominica' => 'Dominica', 'Dominican Republic' => 'Dominican Republic', 'East Timor' => 'East Timor', 'Ecuador' => 'Ecuador', 'Egypt' => 'Egypt', 'El Salvador' => 'El Salvador', 'England' => 'England', 'Equatorial Guinea' => 'Equatorial Guinea', 'Eritrea' => 'Eritrea', 'Espana' => 'Espana', 'Estonia' => 'Estonia', 'Ethiopia' => 'Ethiopia', 'Falkland Islands' => 'Falkland Islands', 'Faroe Islands' => 'Faroe Islands', 'Fiji' => 'Fiji', 'Finland' => 'Finland', 'France' => 'France', 'French Guiana' => 'French Guiana', 'French Polynesia' => 'French Polynesia', 'French Southern Territories' => 'French Southern Territories', 'Gabon' => 'Gabon', 'Gambia' => 'Gambia', 'Georgia' => 'Georgia', 'Germany' => 'Germany', 'Ghana' => 'Ghana', 'Gibraltar' => 'Gibraltar', 'Great Britain' => 'Great Britain', 'Greece' => 'Greece', 'Greenland' => 'Greenland', 'Grenada' => 'Grenada', 'Guadeloupe' => 'Guadeloupe', 'Guam' => 'Guam', 'Guatemala' => 'Guatemala', 'Guinea' => 'Guinea', 'Guinea-Bissau' => 'Guinea-Bissau', 'Guyana' => 'Guyana', 'Haiti' => 'Haiti', 'Heard and Mc Donald Islands' => 'Heard and Mc Donald Islands', 'Honduras' => 'Honduras', 'Hong Kong' => 'Hong Kong', 'Hungary' => 'Hungary', 'Iceland' => 'Iceland', 'India' => 'India', 'Indonesia' => 'Indonesia', 'Ireland' => 'Ireland', 'Israel' => 'Israel', 'Italy' => 'Italy', 'Iran' => 'Iran', 'Iraq' => 'Iraq', 'Jamaica' => 'Jamaica', 'Japan' => 'Japan', 'Jordan' => 'Jordan', 'Kazakhstan' => 'Kazakhstan', 'Kenya' => 'Kenya', 'Kiribati' => 'Kiribati', 'Korea, Republic of', 'Korea (South)' => 'Korea (South)', 'Kuwait' => 'Kuwait', 'Kyrgyzstan' => 'Kyrgyzstan', 'Lao People\'s Democratic Republic' => 'Lao People\'s Democratic Republic', 'Latvia' => 'Latvia', 'Lebanon' => 'Lebanon', 'Lesotho' => 'Lesotho', 'Liberia' => 'Liberia', 'Liechtenstein' => 'Liechtenstein', 'Lithuania' => 'Lithuania', 'Luxembourg' => 'Luxembourg', 'Macau' => 'Macau', 'Macedonia' => 'Macedonia', 'Madagascar' => 'Madagascar', 'Malawi' => 'Malawi', 'Malaysia' => 'Malaysia', 'Maldives' => 'Maldives', 'Mali' => 'Mali', 'Malta' => 'Malta', 'Marshall Islands' => 'Marshall Islands', 'Martinique' => 'Martinique', 'Mauritania' => 'Mauritania', 'Mauritius' => 'Mauritius', 'Mayotte' => 'Mayotte', 'Mexico' => 'Mexico', 'Micronesia, Federated States of', 'Moldova, Republic of', 'Monaco' => 'Monaco', 'Mongolia' => 'Mongolia', 'Montserrat' => 'Montserrat', 'Morocco' => 'Morocco', 'Mozambique' => 'Mozambique', 'Myanmar' => 'Myanmar', 'Namibia' => 'Namibia', 'Nauru' => 'Nauru', 'Nepal' => 'Nepal', 'Netherlands' => 'Netherlands', 'Netherlands Antilles' => 'Netherlands Antilles', 'New Caledonia' => 'New Caledonia', 'New Zealand' => 'New Zealand', 'Nicaragua' => 'Nicaragua', 'Niger' => 'Niger', 'Nigeria' => 'Nigeria', 'Niue' => 'Niue', 'Norfolk Island' => 'Norfolk Island', 'Northern Ireland' => 'Northern Ireland', 'Northern Mariana Islands' => 'Northern Mariana Islands', 'Norway' => 'Norway', 'Oman' => 'Oman', 'Pakistan' => 'Pakistan', 'Palau' => 'Palau', 'Panama' => 'Panama', 'Papua New Guinea' => 'Papua New Guinea', 'Paraguay' => 'Paraguay', 'Peru' => 'Peru', 'Philippines' => 'Philippines', 'Pitcairn' => 'Pitcairn', 'Poland' => 'Poland', 'Portugal' => 'Portugal', 'Puerto Rico' => 'Puerto Rico', 'Qatar' => 'Qatar', 'Reunion' => 'Reunion', 'Romania' => 'Romania', 'Russia' => 'Russia', 'Rwanda' => 'Rwanda', 'Saint Kitts and Nevis' => 'Saint Kitts and Nevis', 'Saint Lucia' => 'Saint Lucia', 'Saint Vincent and the Grenadines' => 'Saint Vincent and the Grenadines', 'Samoa (Independent)' => 'Samoa (Independent)', 'San Marino' => 'San Marino', 'Sao Tome and Principe' => 'Sao Tome and Principe', 'Saudi Arabia' => 'Saudi Arabia', 'Scotland' => 'Scotland', 'Senegal' => 'Senegal', 'Serbia and Montenegro' => 'Serbia and Montenegro', 'Seychelles' => 'Seychelles', 'Sierra Leone' => 'Sierra Leone', 'Singapore' => 'Singapore', 'Slovakia' => 'Slovakia', 'Slovenia' => 'Slovenia', 'Solomon Islands' => 'Solomon Islands', 'Somalia' => 'Somalia', 'South Africa' => 'South Africa', 'South Georgia and the South Sandwich Islands' => 'South Georgia and the South Sandwich Islands', 'South Korea' => 'South Korea', 'Spain' => 'Spain', 'Sri Lanka' => 'Sri Lanka', 'St. Helena' => 'St. Helena', 'St. Pierre and Miquelon' => 'St. Pierre and Miquelon', 'Suriname' => 'Suriname', 'Svalbard and Jan Mayen Islands' => 'Svalbard and Jan Mayen Islands', 'Swaziland' => 'Swaziland', 'Sweden' => 'Sweden', 'Switzerland' => 'Switzerland', 'Taiwan' => 'Taiwan', 'Tajikistan' => 'Tajikistan', 'Tanzania' => 'Tanzania', 'Thailand' => 'Thailand', 'Togo' => 'Togo', 'Tokelau' => 'Tokelau', 'Tonga' => 'Tonga', 'Trinidad' => 'Trinidad', 'Trinidad and Tobago' => 'Trinidad and Tobago', 'Tunisia' => 'Tunisia', 'Turkey' => 'Turkey', 'Turkmenistan' => 'Turkmenistan', 'Turks and Caicos Islands' => 'Turks and Caicos Islands', 'Tuvalu' => 'Tuvalu', 'Uganda' => 'Uganda', 'Ukraine' => 'Ukraine', 'United Arab Emirates' => 'United Arab Emirates', 'United Kingdom' => 'United Kingdom', 'United States' => 'United States', 'United States Minor Outlying Islands' => 'United States Minor Outlying Islands', 'Uruguay' => 'Uruguay', 'Uzbekistan' => 'Uzbekistan', 'Vanuatu' => 'Vanuatu', 'Vatican City State (Holy See)' => 'Vatican City State (Holy See)', 'Venezuela' => 'Venezuela', 'Viet Nam' => 'Viet Nam', 'Virgin Islands (British)' => 'Virgin Islands (British)', 'Virgin Islands (U.S.)' => 'Virgin Islands (U.S.)', 'Wales' => 'Wales', 'Wallis and Futuna Islands' => 'Wallis and Futuna Islands', 'Western Sahara' => 'Western Sahara', 'Yemen' => 'Yemen', 'Zambia' => 'Zambia', 'Zimbabwe' => 'Zimbabwe'); if ($translated) { foreach ($countries as $key => $value) { $countries[$key] = t($value); } } natsort($countries); return $countries; } function _helpers_data_us_states_array($translated = TRUE) { $states = array( 'AL' => 'Alabama', 'AK' => 'Alaska', 'AZ' => 'Arizona', 'AR' => 'Arkansas', 'CA'=> 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DC' => 'D.C.', 'DE' => 'Delaware', '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' => 'NewMexico', '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', ); if ($translated) { foreach ($states as $key => $value) { $states[$key] = t($value); } } natsort($states); return $states; }