ListState.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. /**
  3. * Class NF_Fields_ListState
  4. */
  5. class NF_Fields_ListState extends NF_Abstracts_List
  6. {
  7. protected $_name = 'liststate';
  8. protected $_type = 'liststate';
  9. protected $_nicename = 'US States';
  10. protected $_section = 'userinfo';
  11. protected $_icon = 'map-marker';
  12. protected $_templates = array( 'liststate', 'listselect' );
  13. protected $_old_classname = 'list-select';
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. $this->_nicename = __( 'US States', 'ninja-forms' );
  18. $this->_settings[ 'options' ][ 'value' ] = $this->get_options();
  19. }
  20. private function get_options()
  21. {
  22. $order = 0;
  23. $options = array();
  24. // Option to have no state selected by default.
  25. $options[] = array(
  26. 'label' => '- ' . __( 'Select State', 'ninja-forms' ) . ' -',
  27. 'value' => '',
  28. 'calc' => '',
  29. 'selected' => 0,
  30. 'order' => $order,
  31. );
  32. $order++;
  33. foreach( Ninja_Forms()->config( 'StateList' ) as $label => $value ){
  34. $options[] = array(
  35. 'label' => $label,
  36. 'value' => $value,
  37. 'calc' => '',
  38. 'selected' => 0,
  39. 'order' => $order
  40. );
  41. $order++;
  42. }
  43. return $options;
  44. }
  45. }