-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved states array to the separate class and added Twig extension to …
…display state name
- Loading branch information
Showing
4 changed files
with
143 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace Napas\FormExtraBundle\Misc; | ||
|
||
/** | ||
* US States class | ||
* @package Napas\FormExtraBundle\Misc | ||
*/ | ||
class UsStates | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected static $states = 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', | ||
); | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public static function getChoices() | ||
{ | ||
return self::$states; | ||
} | ||
|
||
/** | ||
* @param $code | ||
* @return null | ||
*/ | ||
public static function getStateName($code) | ||
{ | ||
if (isset(self::$states[$code])) { | ||
return self::$states[$code]; | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Napas\FormExtraBundle\Twig; | ||
|
||
use Napas\FormExtraBundle\Misc\UsStates; | ||
|
||
/** | ||
* Twig extension to display states | ||
* | ||
* @package Napas\FormExtraBundle\Twig | ||
*/ | ||
class StatesExtension extends \Twig_Extension | ||
{ | ||
/** | ||
* Returns the name of the extension. | ||
* | ||
* @return string The extension name | ||
*/ | ||
public function getName() | ||
{ | ||
return 'states_extension'; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getFunctions() | ||
{ | ||
return array( | ||
new \Twig_SimpleFunction( | ||
'state_name', | ||
array( | ||
$this, | ||
'getStateName' | ||
) | ||
), | ||
); | ||
} | ||
|
||
/** | ||
* @param $stateCode | ||
* @return null | ||
*/ | ||
public function getStateName($stateCode) | ||
{ | ||
return UsStates::getStateName($stateCode); | ||
} | ||
} |