commit 7c76e55661fec618c37177d0f148a5033fd57249 Author: Matthew Radcliffe Date: Sat Sep 14 15:42:49 2013 -0400 Issue #2046147 by mradcliffe: Add better comments to filter handler. diff --git a/views/cck_select_other_handler_filter.inc b/views/cck_select_other_handler_filter.inc index 5854820..c64b933 100644 --- a/views/cck_select_other_handler_filter.inc +++ b/views/cck_select_other_handler_filter.inc @@ -1,6 +1,7 @@ options['expose']['identifier']; if (!is_array($form_state['input'][$identifier])) { + // Form input is reduced to one value sometimes, and this causes issues + // with the array parents. $form_state['input'][$identifier] = array( 'select_other_list' => $this->value, 'select_other_text_input' => '', ); } + // Add the javascript settings to the form element. $settings = array( $identifier => array( 'list_element' => str_replace('_', '-', 'edit-' . $identifier . '-select-other-list'), 'input_element' => str_replace('_', '-', 'edit-' . $identifier . '-select-other-text-input'), ), ); - $form[$identifier]['#parents'] = array($identifier); $form[$identifier]['#attached']['js'] = array( array( 'data' => array('CCKSelectOther' => $settings), @@ -47,7 +50,12 @@ class cck_select_other_handler_filter extends views_handler_filter_in_operator { ), drupal_get_path('module', 'cck_select_other') . '/cck_select_other.js', ); + + // Change element parents to use exposed identifier. + $form[$identifier]['#parents'] = array($identifier); $form[$identifier]['select_other_list']['#parents'] = array($identifier, 'select_other_list'); + + // Add the select other text input element. $form[$identifier]['select_other_text_input'] = array( '#type' => 'textfield', '#title' => t('Other'), @@ -59,6 +67,7 @@ class cck_select_other_handler_filter extends views_handler_filter_in_operator { '#size' => 10, ); + // Only display multiple select list when explicitly required. $form[$identifier]['select_other_list']['#multiple'] = $this->options['expose']['multiple']; if (empty($form_state['exposed']) || empty($this->options['expose']['required'])) { @@ -68,6 +77,9 @@ class cck_select_other_handler_filter extends views_handler_filter_in_operator { } } + /** + * @inheritdoc + */ function exposed_submit(&$form, &$form_state) { $identifier = $this->options['expose']['identifier']; $values = $form_state['values'][$identifier]; @@ -99,7 +111,7 @@ class cck_select_other_handler_filter extends views_handler_filter_in_operator { } /** - * Value form + * @inheritdoc */ function value_form(&$form, &$form_state) { parent::value_form($form, $form_state); @@ -107,35 +119,19 @@ class cck_select_other_handler_filter extends views_handler_filter_in_operator { $default = array(); $value_keys = array_keys($this->value_options); - foreach ($this->value as $key => $value) { - // Populate default values based on the value option keys. - if (in_array($value, $value_keys)) { - $default[] = $value; - } - else { - $default[] = 'other'; - } - } - - $settings = array( - 'list_element' => 'edit-value-select-other-list', - 'input_element' => 'edit-value-select-other-text-input', - ); + // Populate default values based on the value option keys. + $default = array_reduce($this->value, function(&$result, $item) use ($value_keys) { + $result[] = in_array($item, $value_keys) ? $item : 'other'; + return $result; + }); $options = $form['value']['#options']; + unset($form['value']['#options']); + $form['value'] = array( '#type' => 'container', '#tree' => TRUE, '#parents' => array('value'), - '#attached' => array( - 'js' => array( - array( - 'data' => array('CCKSelectOther' => $settings), - 'type' => 'setting', - ), - drupal_get_path('module', 'cck_select_other') . '/cck_select_other.js', - ), - ), 'select_other_list' => array( '#type' => 'select', '#options' => $options, @@ -146,6 +142,9 @@ class cck_select_other_handler_filter extends views_handler_filter_in_operator { ); } + /** + * @inheritdoc + */ function value_submit($form, &$form_state) { // Capture the values into a separate array and reset the value array. $values = $form_state['values']['value']; @@ -158,6 +157,9 @@ class cck_select_other_handler_filter extends views_handler_filter_in_operator { } } + /** + * @inheritdoc + */ function get_value_options() { $this->value_options = cck_select_other_options($this->instance); @@ -166,18 +168,23 @@ class cck_select_other_handler_filter extends views_handler_filter_in_operator { unset($this->value_options['_none']); } + /** + * @inheritdoc + */ function accept_exposed_input($input) { $ret = parent::accept_exposed_input($input); return $ret; } + /** + * @inheritdoc + */ function admin_summary() { if (!empty($this->options['exposed'])) { return t('exposed'); } $info = $this->operators(); - $this->get_value_options(); if (!is_array($this->value)) { @@ -202,11 +209,11 @@ class cck_select_other_handler_filter extends views_handler_filter_in_operator { $i++; } - return $operator . (($values !== '') ? ' (' . $values . ')' : ''); + return $operator . (($values !== '') ? ' ' . $values : ''); } /** - * Implements op_simple(). + * @inheritdoc */ function op_simple() { if (empty($this->value) || in_array('All', $this->value)) {