1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use EventEspresso\core\exceptions\InvalidDataTypeException; |
4
|
|
|
use EventEspresso\core\exceptions\InvalidInterfaceException; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* EE_State_Select_Input |
8
|
|
|
* |
9
|
|
|
* @package Event Espresso |
10
|
|
|
* @subpackage |
11
|
|
|
* @author Mike Nelson |
12
|
|
|
*/ |
13
|
|
|
class EE_State_Select_Input extends EE_Select_Input |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var string the name of the EE_State field to use for option values in the HTML form input. |
17
|
|
|
*/ |
18
|
|
|
protected $valueFieldName; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param EE_State[]|array|null $state_options. If a flat array of string is provided, |
|
|
|
|
22
|
|
|
* $input_settings['value_field_name'] is ignored. If an array of states is passed, that field will be used for |
23
|
|
|
* the keys (which will become the option values). If null or empty is passed, all active states will be used, |
24
|
|
|
* and $input_settings['value_field_name'] will again be used. * |
25
|
|
|
* @param array $input_settings same as parent, but also { |
26
|
|
|
* @type string $value_field_name the name of the field to use |
27
|
|
|
* for the HTML option values, ie, `STA_ID`, `STA_abbrev`, or `STA_name`. |
28
|
|
|
* } |
29
|
|
|
* @throws EE_Error |
30
|
|
|
* @throws InvalidArgumentException |
31
|
|
|
* @throws InvalidDataTypeException |
32
|
|
|
* @throws InvalidInterfaceException |
33
|
|
|
* @throws ReflectionException |
34
|
|
|
*/ |
35
|
|
|
public function __construct($state_options, $input_settings = array()) |
36
|
|
|
{ |
37
|
|
|
if (isset($input_settings['value_field_name'])) { |
38
|
|
|
$this->valueFieldName = $input_settings['value_field_name']; |
39
|
|
|
if (! EEM_State::instance()->has_field((string) $this->valueFieldName())) { |
40
|
|
|
throw new InvalidArgumentException( |
41
|
|
|
sprintf( |
42
|
|
|
esc_html__('An invalid state field "%1$s" was specified for the state input\'s option values.', 'event_espresso'), |
43
|
|
|
$this->valueFieldName() |
44
|
|
|
) |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
} else { |
48
|
|
|
$this->valueFieldName = 'STA_ID'; |
49
|
|
|
} |
50
|
|
|
$state_options = apply_filters( |
51
|
|
|
'FHEE__EE_State_Select_Input____construct__state_options', |
52
|
|
|
$this->get_state_answer_options($state_options), |
53
|
|
|
$this |
54
|
|
|
); |
55
|
|
|
$input_settings['html_class'] = isset($input_settings['html_class']) |
56
|
|
|
? $input_settings['html_class'] . ' ee-state-select-js' |
57
|
|
|
: 'ee-state-select-js'; |
58
|
|
|
parent::__construct($state_options, $input_settings); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Returns the name of the state field used for the HTML option values. |
63
|
|
|
* @since $VID:$ |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
|
|
public function valueFieldName() |
67
|
|
|
{ |
68
|
|
|
return $this->valueFieldName; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* get_state_answer_options |
74
|
|
|
* |
75
|
|
|
* @param array $state_options |
76
|
|
|
* @return array |
77
|
|
|
* @throws EE_Error |
78
|
|
|
* @throws InvalidArgumentException |
79
|
|
|
* @throws ReflectionException |
80
|
|
|
* @throws InvalidDataTypeException |
81
|
|
|
* @throws InvalidInterfaceException |
82
|
|
|
*/ |
83
|
|
|
public function get_state_answer_options($state_options = null) |
84
|
|
|
{ |
85
|
|
|
// if passed something that is NOT an array |
86
|
|
|
if (! is_array($state_options) || empty($state_options)) { |
87
|
|
|
// get possibly cached list of states |
88
|
|
|
$states = EEM_State::instance()->get_all_active_states(); |
89
|
|
|
} |
90
|
|
|
if (is_array($state_options) && reset($state_options) instanceof EE_State) { |
91
|
|
|
$states = $state_options; |
92
|
|
|
$state_options = array(); |
93
|
|
|
} |
94
|
|
|
if (! empty($states)) { |
95
|
|
|
// set the default |
96
|
|
|
$state_options[''][''] = ''; |
97
|
|
View Code Duplication |
foreach ($states as $state) { |
|
|
|
|
98
|
|
|
if ($state instanceof EE_State) { |
99
|
|
|
$state_options[ $state->country()->name() ][ $state->get($this->valueFieldName()) ] = $state->name(); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
return $state_options; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.