@@ -15,80 +15,80 @@ |
||
| 15 | 15 | class EE_Select2_Display_Strategy extends EE_Select_Display_Strategy |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Arguments that will be passed into the select2 javascript constructor |
|
| 20 | - * @var array |
|
| 21 | - */ |
|
| 22 | - protected $_select2_js_args = array(); |
|
| 18 | + /** |
|
| 19 | + * Arguments that will be passed into the select2 javascript constructor |
|
| 20 | + * @var array |
|
| 21 | + */ |
|
| 22 | + protected $_select2_js_args = array(); |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * |
|
| 26 | - * @param array $select2_js_args pass in the EXACT array of JS arguments you want |
|
| 27 | - * to pass into the select2 js/html input. See https://select2.github.io |
|
| 28 | - */ |
|
| 29 | - public function __construct($select2_js_args = array()) |
|
| 30 | - { |
|
| 31 | - $this->_select2_js_args = $select2_js_args; |
|
| 32 | - parent::__construct(); |
|
| 33 | - } |
|
| 24 | + /** |
|
| 25 | + * |
|
| 26 | + * @param array $select2_js_args pass in the EXACT array of JS arguments you want |
|
| 27 | + * to pass into the select2 js/html input. See https://select2.github.io |
|
| 28 | + */ |
|
| 29 | + public function __construct($select2_js_args = array()) |
|
| 30 | + { |
|
| 31 | + $this->_select2_js_args = $select2_js_args; |
|
| 32 | + parent::__construct(); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * enqueues the select2 initializing js (which depends on the select2 js) and |
|
| 37 | - * the select2 css |
|
| 38 | - */ |
|
| 39 | - public function enqueue_js() |
|
| 40 | - { |
|
| 41 | - // need to first deregister the select2 script in case some other plugin **cough cough Toolset Types cough** |
|
| 42 | - // is carelessly registering an older version of Select2 on admin pages that don't even belong to them |
|
| 43 | - wp_deregister_script('select2'); |
|
| 44 | - wp_deregister_style('select2'); |
|
| 45 | - wp_register_script('select2', EE_GLOBAL_ASSETS_URL . 'scripts/select2.min.js', array(), '4.0.2', true); |
|
| 46 | - wp_register_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all'); |
|
| 47 | - wp_enqueue_script('form_section_select2_init', EE_GLOBAL_ASSETS_URL . 'scripts/form_section_select2_init.js', array( 'select2' ), '1.0.0', true); |
|
| 48 | - wp_enqueue_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all'); |
|
| 49 | - } |
|
| 35 | + /** |
|
| 36 | + * enqueues the select2 initializing js (which depends on the select2 js) and |
|
| 37 | + * the select2 css |
|
| 38 | + */ |
|
| 39 | + public function enqueue_js() |
|
| 40 | + { |
|
| 41 | + // need to first deregister the select2 script in case some other plugin **cough cough Toolset Types cough** |
|
| 42 | + // is carelessly registering an older version of Select2 on admin pages that don't even belong to them |
|
| 43 | + wp_deregister_script('select2'); |
|
| 44 | + wp_deregister_style('select2'); |
|
| 45 | + wp_register_script('select2', EE_GLOBAL_ASSETS_URL . 'scripts/select2.min.js', array(), '4.0.2', true); |
|
| 46 | + wp_register_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all'); |
|
| 47 | + wp_enqueue_script('form_section_select2_init', EE_GLOBAL_ASSETS_URL . 'scripts/form_section_select2_init.js', array( 'select2' ), '1.0.0', true); |
|
| 48 | + wp_enqueue_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all'); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Gets the javascript args which will be localized and passed into the select2 js/html input |
|
| 53 | - * @return array |
|
| 54 | - */ |
|
| 55 | - public function get_js_args() |
|
| 56 | - { |
|
| 57 | - return $this->_select2_js_args; |
|
| 58 | - } |
|
| 51 | + /** |
|
| 52 | + * Gets the javascript args which will be localized and passed into the select2 js/html input |
|
| 53 | + * @return array |
|
| 54 | + */ |
|
| 55 | + public function get_js_args() |
|
| 56 | + { |
|
| 57 | + return $this->_select2_js_args; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Sets the exact js args which will be passed into the select2 js/html input |
|
| 62 | - * @param array $js_args |
|
| 63 | - */ |
|
| 64 | - public function set_js_args($js_args) |
|
| 65 | - { |
|
| 66 | - $this->_select2_js_args = $js_args; |
|
| 67 | - } |
|
| 60 | + /** |
|
| 61 | + * Sets the exact js args which will be passed into the select2 js/html input |
|
| 62 | + * @param array $js_args |
|
| 63 | + */ |
|
| 64 | + public function set_js_args($js_args) |
|
| 65 | + { |
|
| 66 | + $this->_select2_js_args = $js_args; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Adds select2 data for localization |
|
| 71 | - * @param array $other_js_data |
|
| 72 | - * @return array |
|
| 73 | - */ |
|
| 74 | - public function get_other_js_data($other_js_data = array()) |
|
| 75 | - { |
|
| 76 | - $other_js_data = parent::get_other_js_data($other_js_data); |
|
| 77 | - if (! isset($other_js_data['select2s'])) { |
|
| 78 | - $other_js_data['select2s'] = array(); |
|
| 79 | - } |
|
| 80 | - $other_js_data['select2s'][ $this->_input->html_id() ] = $this->get_js_args(); |
|
| 81 | - return $other_js_data; |
|
| 82 | - } |
|
| 69 | + /** |
|
| 70 | + * Adds select2 data for localization |
|
| 71 | + * @param array $other_js_data |
|
| 72 | + * @return array |
|
| 73 | + */ |
|
| 74 | + public function get_other_js_data($other_js_data = array()) |
|
| 75 | + { |
|
| 76 | + $other_js_data = parent::get_other_js_data($other_js_data); |
|
| 77 | + if (! isset($other_js_data['select2s'])) { |
|
| 78 | + $other_js_data['select2s'] = array(); |
|
| 79 | + } |
|
| 80 | + $other_js_data['select2s'][ $this->_input->html_id() ] = $this->get_js_args(); |
|
| 81 | + return $other_js_data; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Overrides standard attributes array to add the CSS class "ee-select2" |
|
| 86 | - * @return array |
|
| 87 | - */ |
|
| 88 | - protected function _standard_attributes_array() |
|
| 89 | - { |
|
| 90 | - $standard_attributes = parent::_standard_attributes_array(); |
|
| 91 | - $standard_attributes['class'] .= ' ee-select2'; |
|
| 92 | - return $standard_attributes; |
|
| 93 | - } |
|
| 84 | + /** |
|
| 85 | + * Overrides standard attributes array to add the CSS class "ee-select2" |
|
| 86 | + * @return array |
|
| 87 | + */ |
|
| 88 | + protected function _standard_attributes_array() |
|
| 89 | + { |
|
| 90 | + $standard_attributes = parent::_standard_attributes_array(); |
|
| 91 | + $standard_attributes['class'] .= ' ee-select2'; |
|
| 92 | + return $standard_attributes; |
|
| 93 | + } |
|
| 94 | 94 | } |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | // is carelessly registering an older version of Select2 on admin pages that don't even belong to them |
| 43 | 43 | wp_deregister_script('select2'); |
| 44 | 44 | wp_deregister_style('select2'); |
| 45 | - wp_register_script('select2', EE_GLOBAL_ASSETS_URL . 'scripts/select2.min.js', array(), '4.0.2', true); |
|
| 46 | - wp_register_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all'); |
|
| 47 | - wp_enqueue_script('form_section_select2_init', EE_GLOBAL_ASSETS_URL . 'scripts/form_section_select2_init.js', array( 'select2' ), '1.0.0', true); |
|
| 48 | - wp_enqueue_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all'); |
|
| 45 | + wp_register_script('select2', EE_GLOBAL_ASSETS_URL.'scripts/select2.min.js', array(), '4.0.2', true); |
|
| 46 | + wp_register_style('select2', EE_GLOBAL_ASSETS_URL.'css/select2.min.css', array(), '4.0.2', 'all'); |
|
| 47 | + wp_enqueue_script('form_section_select2_init', EE_GLOBAL_ASSETS_URL.'scripts/form_section_select2_init.js', array('select2'), '1.0.0', true); |
|
| 48 | + wp_enqueue_style('select2', EE_GLOBAL_ASSETS_URL.'css/select2.min.css', array(), '4.0.2', 'all'); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -74,10 +74,10 @@ discard block |
||
| 74 | 74 | public function get_other_js_data($other_js_data = array()) |
| 75 | 75 | { |
| 76 | 76 | $other_js_data = parent::get_other_js_data($other_js_data); |
| 77 | - if (! isset($other_js_data['select2s'])) { |
|
| 77 | + if ( ! isset($other_js_data['select2s'])) { |
|
| 78 | 78 | $other_js_data['select2s'] = array(); |
| 79 | 79 | } |
| 80 | - $other_js_data['select2s'][ $this->_input->html_id() ] = $this->get_js_args(); |
|
| 80 | + $other_js_data['select2s'][$this->_input->html_id()] = $this->get_js_args(); |
|
| 81 | 81 | return $other_js_data; |
| 82 | 82 | } |
| 83 | 83 | |
@@ -166,12 +166,12 @@ discard block |
||
| 166 | 166 | $values_for_options = (array) $value; |
| 167 | 167 | $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
| 168 | 168 | $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
| 169 | - $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
| 170 | - $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
| 169 | + $this->_extra_select_columns[] = $value_field->get_qualified_column().' AS '.$this->_value_field_name; |
|
| 170 | + $this->_extra_select_columns[] = $display_field->get_qualified_column().' AS '.$this->_display_field_name; |
|
| 171 | 171 | $display_values = $this->_get_model()->get_all_wpdb_results( |
| 172 | 172 | array( |
| 173 | 173 | array( |
| 174 | - $this->_value_field_name => array( 'IN', $values_for_options ) |
|
| 174 | + $this->_value_field_name => array('IN', $values_for_options) |
|
| 175 | 175 | ) |
| 176 | 176 | ), |
| 177 | 177 | ARRAY_A, |
@@ -181,9 +181,9 @@ discard block |
||
| 181 | 181 | if (is_array($select_options)) { |
| 182 | 182 | foreach ($display_values as $db_rows) { |
| 183 | 183 | $db_rows = (array) $db_rows; |
| 184 | - $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
| 184 | + $select_options[$db_rows[$this->_value_field_name]] = apply_filters( |
|
| 185 | 185 | 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
| 186 | - $db_rows[ $this->_display_field_name ], |
|
| 186 | + $db_rows[$this->_display_field_name], |
|
| 187 | 187 | $db_rows |
| 188 | 188 | ); |
| 189 | 189 | } |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | */ |
| 200 | 200 | protected function _get_model() |
| 201 | 201 | { |
| 202 | - if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
| 202 | + if ( ! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
| 203 | 203 | throw new EE_Error( |
| 204 | 204 | sprintf( |
| 205 | 205 | __( |
@@ -17,200 +17,200 @@ |
||
| 17 | 17 | class EE_Select_Ajax_Model_Rest_Input extends EE_Form_Input_With_Options_Base |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var string $_model_name |
|
| 22 | - */ |
|
| 23 | - protected $_model_name; |
|
| 20 | + /** |
|
| 21 | + * @var string $_model_name |
|
| 22 | + */ |
|
| 23 | + protected $_model_name; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var string $_display_field_name |
|
| 27 | - */ |
|
| 28 | - protected $_display_field_name; |
|
| 25 | + /** |
|
| 26 | + * @var string $_display_field_name |
|
| 27 | + */ |
|
| 28 | + protected $_display_field_name; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @var string $_value_field_name |
|
| 32 | - */ |
|
| 33 | - protected $_value_field_name; |
|
| 30 | + /** |
|
| 31 | + * @var string $_value_field_name |
|
| 32 | + */ |
|
| 33 | + protected $_value_field_name; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var array $_extra_select_columns |
|
| 37 | - */ |
|
| 38 | - protected $_extra_select_columns = array(); |
|
| 35 | + /** |
|
| 36 | + * @var array $_extra_select_columns |
|
| 37 | + */ |
|
| 38 | + protected $_extra_select_columns = array(); |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @param array $input_settings { |
|
| 43 | - * @type string $model_name the name of model to be used for searching, both via the REST API and server-side model queries |
|
| 44 | - * @type array $query_params default query parameters which will apply to both REST API queries and server-side queries. This should be |
|
| 45 | - * in the exact format that will be used for server-side model usage (eg use index 0 for where conditions, not |
|
| 46 | - * the string "where") |
|
| 47 | - * @type string $value_field_name the name of the model field on this model to |
|
| 48 | - * be used for the HTML select's option's values |
|
| 49 | - * @type string $display_field_name the name of the model field on this model |
|
| 50 | - * to be used for the HTML select's option's display text |
|
| 51 | - * @type array $select2_args arguments to be passed directly into the select2's JS constructor |
|
| 52 | - * } |
|
| 53 | - * And the arguments accepted by EE_Form_Input_With_Options_Base |
|
| 54 | - * } |
|
| 55 | - * @throws EE_Error |
|
| 56 | - * @throws InvalidArgumentException |
|
| 57 | - * @throws InvalidDataTypeException |
|
| 58 | - * @throws InvalidInterfaceException |
|
| 59 | - */ |
|
| 60 | - public function __construct($input_settings = array()) |
|
| 61 | - { |
|
| 62 | - // needed input settings: |
|
| 63 | - // select2_args |
|
| 64 | - $this->_model_name = EEH_Array::is_set( |
|
| 65 | - $input_settings, |
|
| 66 | - 'model_name', |
|
| 67 | - null |
|
| 68 | - ); |
|
| 69 | - $model = $this->_get_model(); |
|
| 70 | - $query_params = EEH_Array::is_set( |
|
| 71 | - $input_settings, |
|
| 72 | - 'query_params', |
|
| 73 | - array() |
|
| 74 | - ); |
|
| 75 | - // Make sure limit and caps are always set. |
|
| 76 | - $query_params = array_merge( |
|
| 77 | - [ |
|
| 78 | - 'limit' => 10, |
|
| 79 | - 'caps' => EEM_Base::caps_read_admin |
|
| 80 | - ], |
|
| 81 | - $query_params |
|
| 82 | - ); |
|
| 41 | + /** |
|
| 42 | + * @param array $input_settings { |
|
| 43 | + * @type string $model_name the name of model to be used for searching, both via the REST API and server-side model queries |
|
| 44 | + * @type array $query_params default query parameters which will apply to both REST API queries and server-side queries. This should be |
|
| 45 | + * in the exact format that will be used for server-side model usage (eg use index 0 for where conditions, not |
|
| 46 | + * the string "where") |
|
| 47 | + * @type string $value_field_name the name of the model field on this model to |
|
| 48 | + * be used for the HTML select's option's values |
|
| 49 | + * @type string $display_field_name the name of the model field on this model |
|
| 50 | + * to be used for the HTML select's option's display text |
|
| 51 | + * @type array $select2_args arguments to be passed directly into the select2's JS constructor |
|
| 52 | + * } |
|
| 53 | + * And the arguments accepted by EE_Form_Input_With_Options_Base |
|
| 54 | + * } |
|
| 55 | + * @throws EE_Error |
|
| 56 | + * @throws InvalidArgumentException |
|
| 57 | + * @throws InvalidDataTypeException |
|
| 58 | + * @throws InvalidInterfaceException |
|
| 59 | + */ |
|
| 60 | + public function __construct($input_settings = array()) |
|
| 61 | + { |
|
| 62 | + // needed input settings: |
|
| 63 | + // select2_args |
|
| 64 | + $this->_model_name = EEH_Array::is_set( |
|
| 65 | + $input_settings, |
|
| 66 | + 'model_name', |
|
| 67 | + null |
|
| 68 | + ); |
|
| 69 | + $model = $this->_get_model(); |
|
| 70 | + $query_params = EEH_Array::is_set( |
|
| 71 | + $input_settings, |
|
| 72 | + 'query_params', |
|
| 73 | + array() |
|
| 74 | + ); |
|
| 75 | + // Make sure limit and caps are always set. |
|
| 76 | + $query_params = array_merge( |
|
| 77 | + [ |
|
| 78 | + 'limit' => 10, |
|
| 79 | + 'caps' => EEM_Base::caps_read_admin |
|
| 80 | + ], |
|
| 81 | + $query_params |
|
| 82 | + ); |
|
| 83 | 83 | |
| 84 | - // And default to showing the most recently created items first. |
|
| 85 | - if ($model->has_primary_key_field()) { |
|
| 86 | - $query_params['order_by'] = [ |
|
| 87 | - $model->primary_key_name() => 'DESC' |
|
| 88 | - ]; |
|
| 89 | - } |
|
| 84 | + // And default to showing the most recently created items first. |
|
| 85 | + if ($model->has_primary_key_field()) { |
|
| 86 | + $query_params['order_by'] = [ |
|
| 87 | + $model->primary_key_name() => 'DESC' |
|
| 88 | + ]; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - $this->_value_field_name = EEH_Array::is_set( |
|
| 92 | - $input_settings, |
|
| 93 | - 'value_field_name', |
|
| 94 | - $model->primary_key_name() |
|
| 95 | - ); |
|
| 96 | - $this->_display_field_name = EEH_Array::is_set( |
|
| 97 | - $input_settings, |
|
| 98 | - 'display_field_name', |
|
| 99 | - $model->get_a_field_of_type('EE_Text_Field_Base')->get_name() |
|
| 100 | - ); |
|
| 101 | - $this->_extra_select_columns = EEH_Array::is_set( |
|
| 102 | - $input_settings, |
|
| 103 | - 'extra_select_columns', |
|
| 104 | - array() |
|
| 105 | - ); |
|
| 106 | - $this->_add_validation_strategy( |
|
| 107 | - new EE_Model_Matching_Query_Validation_Strategy( |
|
| 108 | - '', |
|
| 109 | - $this->_model_name, |
|
| 110 | - $query_params, |
|
| 111 | - $this->_value_field_name |
|
| 112 | - ) |
|
| 113 | - ); |
|
| 114 | - // get resource endpoint |
|
| 115 | - $rest_controller = LoaderFactory::getLoader()->getNew( |
|
| 116 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read' |
|
| 117 | - ); |
|
| 118 | - $rest_controller->setRequestedVersion(EED_Core_Rest_Api::latest_rest_api_version()); |
|
| 119 | - $default_select2_args = array( |
|
| 120 | - 'ajax' => array( |
|
| 121 | - 'url' => $rest_controller->getVersionedLinkTo( |
|
| 122 | - EEH_Inflector::pluralize_and_lower($this->_model_name) |
|
| 123 | - ), |
|
| 124 | - 'dataType' => 'json', |
|
| 125 | - 'delay' => '250', |
|
| 126 | - 'data_interface' => 'EE_Select2_REST_API_Interface', |
|
| 127 | - 'data_interface_args' => array( |
|
| 128 | - 'default_query_params' => (object) ModelDataTranslator::prepareQueryParamsForRestApi( |
|
| 129 | - $query_params, |
|
| 130 | - $model |
|
| 131 | - ), |
|
| 132 | - 'display_field' => $this->_display_field_name, |
|
| 133 | - 'value_field' => $this->_value_field_name, |
|
| 134 | - 'nonce' => wp_create_nonce('wp_rest'), |
|
| 135 | - 'locale' => str_replace('_', '-', strtolower(get_locale())) |
|
| 136 | - ), |
|
| 137 | - ), |
|
| 138 | - 'cache' => true, |
|
| 139 | - 'width' => 'resolve' |
|
| 140 | - ); |
|
| 141 | - $select2_args = array_replace_recursive( |
|
| 142 | - $default_select2_args, |
|
| 143 | - (array) EEH_Array::is_set($input_settings, 'select2_args', array()) |
|
| 144 | - ); |
|
| 145 | - $this->set_display_strategy(new EE_Select2_Display_Strategy($select2_args)); |
|
| 146 | - parent::__construct(array(), $input_settings); |
|
| 147 | - } |
|
| 91 | + $this->_value_field_name = EEH_Array::is_set( |
|
| 92 | + $input_settings, |
|
| 93 | + 'value_field_name', |
|
| 94 | + $model->primary_key_name() |
|
| 95 | + ); |
|
| 96 | + $this->_display_field_name = EEH_Array::is_set( |
|
| 97 | + $input_settings, |
|
| 98 | + 'display_field_name', |
|
| 99 | + $model->get_a_field_of_type('EE_Text_Field_Base')->get_name() |
|
| 100 | + ); |
|
| 101 | + $this->_extra_select_columns = EEH_Array::is_set( |
|
| 102 | + $input_settings, |
|
| 103 | + 'extra_select_columns', |
|
| 104 | + array() |
|
| 105 | + ); |
|
| 106 | + $this->_add_validation_strategy( |
|
| 107 | + new EE_Model_Matching_Query_Validation_Strategy( |
|
| 108 | + '', |
|
| 109 | + $this->_model_name, |
|
| 110 | + $query_params, |
|
| 111 | + $this->_value_field_name |
|
| 112 | + ) |
|
| 113 | + ); |
|
| 114 | + // get resource endpoint |
|
| 115 | + $rest_controller = LoaderFactory::getLoader()->getNew( |
|
| 116 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read' |
|
| 117 | + ); |
|
| 118 | + $rest_controller->setRequestedVersion(EED_Core_Rest_Api::latest_rest_api_version()); |
|
| 119 | + $default_select2_args = array( |
|
| 120 | + 'ajax' => array( |
|
| 121 | + 'url' => $rest_controller->getVersionedLinkTo( |
|
| 122 | + EEH_Inflector::pluralize_and_lower($this->_model_name) |
|
| 123 | + ), |
|
| 124 | + 'dataType' => 'json', |
|
| 125 | + 'delay' => '250', |
|
| 126 | + 'data_interface' => 'EE_Select2_REST_API_Interface', |
|
| 127 | + 'data_interface_args' => array( |
|
| 128 | + 'default_query_params' => (object) ModelDataTranslator::prepareQueryParamsForRestApi( |
|
| 129 | + $query_params, |
|
| 130 | + $model |
|
| 131 | + ), |
|
| 132 | + 'display_field' => $this->_display_field_name, |
|
| 133 | + 'value_field' => $this->_value_field_name, |
|
| 134 | + 'nonce' => wp_create_nonce('wp_rest'), |
|
| 135 | + 'locale' => str_replace('_', '-', strtolower(get_locale())) |
|
| 136 | + ), |
|
| 137 | + ), |
|
| 138 | + 'cache' => true, |
|
| 139 | + 'width' => 'resolve' |
|
| 140 | + ); |
|
| 141 | + $select2_args = array_replace_recursive( |
|
| 142 | + $default_select2_args, |
|
| 143 | + (array) EEH_Array::is_set($input_settings, 'select2_args', array()) |
|
| 144 | + ); |
|
| 145 | + $this->set_display_strategy(new EE_Select2_Display_Strategy($select2_args)); |
|
| 146 | + parent::__construct(array(), $input_settings); |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | 149 | |
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * Before setting the raw value (usually because we're setting the default, |
|
| 153 | - * or we've received a form submission and this might be re-displayed to the user), |
|
| 154 | - * sets the options so that the current selections appear on initial display. |
|
| 155 | - * |
|
| 156 | - * Note: because this input uses EE_Model_Matching_Query_Validation_Strategy |
|
| 157 | - * for validation, this input's options only affect DISPLAY and NOT validation, |
|
| 158 | - * which is why its ok to just assume the provided $value to be in the list of acceptable values |
|
| 159 | - * |
|
| 160 | - * @param mixed $value |
|
| 161 | - * @return void |
|
| 162 | - * @throws \EE_Error |
|
| 163 | - */ |
|
| 164 | - public function _set_raw_value($value) |
|
| 165 | - { |
|
| 166 | - $values_for_options = (array) $value; |
|
| 167 | - $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
|
| 168 | - $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
|
| 169 | - $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
| 170 | - $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
| 171 | - $display_values = $this->_get_model()->get_all_wpdb_results( |
|
| 172 | - array( |
|
| 173 | - array( |
|
| 174 | - $this->_value_field_name => array( 'IN', $values_for_options ) |
|
| 175 | - ) |
|
| 176 | - ), |
|
| 177 | - ARRAY_A, |
|
| 178 | - implode(',', $this->_extra_select_columns) |
|
| 179 | - ); |
|
| 180 | - $select_options = array(); |
|
| 181 | - if (is_array($select_options)) { |
|
| 182 | - foreach ($display_values as $db_rows) { |
|
| 183 | - $db_rows = (array) $db_rows; |
|
| 184 | - $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
| 185 | - 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
|
| 186 | - $db_rows[ $this->_display_field_name ], |
|
| 187 | - $db_rows |
|
| 188 | - ); |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - $this->set_select_options($select_options); |
|
| 192 | - parent::_set_raw_value($value); |
|
| 193 | - } |
|
| 151 | + /** |
|
| 152 | + * Before setting the raw value (usually because we're setting the default, |
|
| 153 | + * or we've received a form submission and this might be re-displayed to the user), |
|
| 154 | + * sets the options so that the current selections appear on initial display. |
|
| 155 | + * |
|
| 156 | + * Note: because this input uses EE_Model_Matching_Query_Validation_Strategy |
|
| 157 | + * for validation, this input's options only affect DISPLAY and NOT validation, |
|
| 158 | + * which is why its ok to just assume the provided $value to be in the list of acceptable values |
|
| 159 | + * |
|
| 160 | + * @param mixed $value |
|
| 161 | + * @return void |
|
| 162 | + * @throws \EE_Error |
|
| 163 | + */ |
|
| 164 | + public function _set_raw_value($value) |
|
| 165 | + { |
|
| 166 | + $values_for_options = (array) $value; |
|
| 167 | + $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
|
| 168 | + $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
|
| 169 | + $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
| 170 | + $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
| 171 | + $display_values = $this->_get_model()->get_all_wpdb_results( |
|
| 172 | + array( |
|
| 173 | + array( |
|
| 174 | + $this->_value_field_name => array( 'IN', $values_for_options ) |
|
| 175 | + ) |
|
| 176 | + ), |
|
| 177 | + ARRAY_A, |
|
| 178 | + implode(',', $this->_extra_select_columns) |
|
| 179 | + ); |
|
| 180 | + $select_options = array(); |
|
| 181 | + if (is_array($select_options)) { |
|
| 182 | + foreach ($display_values as $db_rows) { |
|
| 183 | + $db_rows = (array) $db_rows; |
|
| 184 | + $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
| 185 | + 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
|
| 186 | + $db_rows[ $this->_display_field_name ], |
|
| 187 | + $db_rows |
|
| 188 | + ); |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + $this->set_select_options($select_options); |
|
| 192 | + parent::_set_raw_value($value); |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * Returns the model, or throws an exception if the model name provided in constructor doesn't exist |
|
| 197 | - * @return EEM_Base |
|
| 198 | - * @throws EE_Error |
|
| 199 | - */ |
|
| 200 | - protected function _get_model() |
|
| 201 | - { |
|
| 202 | - if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
| 203 | - throw new EE_Error( |
|
| 204 | - sprintf( |
|
| 205 | - __( |
|
| 206 | - '%1$s is not a proper model name. Please provide a model name in the "model_name" form input argument', |
|
| 207 | - 'event_espresso' |
|
| 208 | - ), |
|
| 209 | - $this->_model_name |
|
| 210 | - ) |
|
| 211 | - ); |
|
| 212 | - } else { |
|
| 213 | - return EE_Registry::instance()->load_model($this->_model_name); |
|
| 214 | - } |
|
| 215 | - } |
|
| 195 | + /** |
|
| 196 | + * Returns the model, or throws an exception if the model name provided in constructor doesn't exist |
|
| 197 | + * @return EEM_Base |
|
| 198 | + * @throws EE_Error |
|
| 199 | + */ |
|
| 200 | + protected function _get_model() |
|
| 201 | + { |
|
| 202 | + if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
| 203 | + throw new EE_Error( |
|
| 204 | + sprintf( |
|
| 205 | + __( |
|
| 206 | + '%1$s is not a proper model name. Please provide a model name in the "model_name" form input argument', |
|
| 207 | + 'event_espresso' |
|
| 208 | + ), |
|
| 209 | + $this->_model_name |
|
| 210 | + ) |
|
| 211 | + ); |
|
| 212 | + } else { |
|
| 213 | + return EE_Registry::instance()->load_model($this->_model_name); |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | 216 | } |