Skip to content

Instantly share code, notes, and snippets.

@stevelacey
Created April 18, 2012 08:59
Show Gist options
  • Save stevelacey/2412179 to your computer and use it in GitHub Desktop.
Save stevelacey/2412179 to your computer and use it in GitHub Desktop.
sfWidgetFormCountyChoice
<?php
class sfWidgetFormCountyChoice extends sfWidgetFormChoice {
/**
* Constructor.
*
* Available options:
*
* * choices: An array of possible choices (defaults to counties)
* * multiple: true if the select tag must allow multiple selections
* * expanded: true to display an expanded widget
* if expanded is false, then the widget will be a select
* if expanded is true and multiple is false, then the widget will be a list of radio
* if expanded is true and multiple is true, then the widget will be a list of checkbox
* * renderer_class: The class to use instead of the default ones
* * renderer_options: The options to pass to the renderer constructor
* * renderer: A renderer widget (overrides the expanded and renderer_options options)
* The choices option must be: new sfCallable($thisWidgetInstance, 'getChoices')
* @param array $options An array of options
* @param array $attributes An array of default HTML attributes
*
* @see sfWidgetFormChoiceBase
*/
protected function configure($options = array(), $attributes = array())
{
parent::configure($options, $attributes);
// Source: http://www.carronmedia.com/uk-postal-counties-list
$this->addOption('choices', array(
'' => '-- Please Select --',
'England' => array(
'Avon',
'Bedfordshire',
'Berkshire',
'Buckinghamshire',
'Cambridgeshire',
'Cheshire',
'Cleveland',
'Cornwall',
'Cumbria',
'Derbyshire',
'Devon',
'Dorset',
'Durham',
'East Sussex',
'Essex',
'Gloucestershire',
'Hampshire',
'Herefordshire',
'Hertfordshire',
'Isle of Wight',
'Kent',
'Lancashire',
'Leicestershire',
'Lincolnshire',
'London',
'Merseyside',
'Middlesex',
'Norfolk',
'Northamptonshire',
'Northumberland',
'North Humberside',
'North Yorkshire',
'Nottinghamshire',
'Oxfordshire',
'Rutland',
'Shropshire',
'Somerset',
'South Humberside',
'South Yorkshire',
'Staffordshire',
'Suffolk',
'Surrey',
'Tyne and Wear',
'Warwickshire',
'West Midlands',
'West Sussex',
'West Yorkshire',
'Wiltshire',
'Worcestershire'
),
'Wales' => array(
'Clwyd',
'Dyfed',
'Gwent',
'Gwynedd',
'Mid Glamorgan',
'Powys',
'South Glamorgan',
'West Glamorgan'
),
'Scotland' => array(
'Aberdeenshire',
'Angus',
'Argyll',
'Ayrshire',
'Banffshire',
'Berwickshire',
'Bute',
'Caithness',
'Clackmannanshire',
'Dumfriesshire',
'Dunbartonshire',
'East Lothian',
'Fife',
'Inverness-shire',
'Kincardineshire',
'Kinross-shire',
'Kirkcudbrightshire',
'Lanarkshire',
'Midlothian',
'Moray',
'Nairnshire',
'Orkney',
'Peeblesshire',
'Perthshire',
'Renfrewshire',
'Ross-shire',
'Roxburghshire',
'Selkirkshire',
'Shetland',
'Stirlingshire',
'Sutherland',
'West Lothian',
'Wigtownshire'
),
'Northern Ireland' => array(
'Antrim',
'Armagh',
'Down',
'Fermanagh',
'Londonderry',
'Tyrone'
)
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment