diff --git a/views_php_array_plugin_style_php_array.inc b/views_php_array_plugin_style_php_array.inc index 4f1f155..8d9374f 100644 --- a/views_php_array_plugin_style_php_array.inc +++ b/views_php_array_plugin_style_php_array.inc @@ -12,6 +12,38 @@ */ class views_php_array_plugin_style_php_array extends views_plugin_style { + function options_form(&$form, &$form_state) { + parent::options_form(&$form, &$form_state); + $form['shallow'] = array( + '#type' => 'checkbox', + '#title' => t('Produce a shallow array'), + '#default_value' => $this->options['shallow'], + ); + $options = array('' => t('')); + foreach ($this->display->handler->get_handlers('field') as $field => $handler) { + + if ($label = $handler->label()) { + $options[$field] = $label; + } + else { + $options[$field] = $handler->ui_name(); + } + } + + $form['key_field'] = array( + '#type' => 'select', + '#title' => t('Field to use for the array key'), + '#options' => $options, + '#default_value' => $this->options['key_field'], + ); + $form['value_field'] = array( + '#type' => 'select', + '#title' => t('Field to use for the value'), + '#options' => $options, + '#default_value' => $this->options['value_field'], + ); + } + function render() { // Group the rows according to the grouping field, if specified. $sets = $this->render_grouping($this->view->result, $this->options['grouping']); @@ -23,6 +55,9 @@ class views_php_array_plugin_style_php_array extends views_plugin_style { // Make sure fields are rendered $this->render_fields($this->view->result); $sets = array(); + $shallow = $this->options['shallow']; + $key_field = $this->options['key_field']; + $value_field = $this->options['value_field']; // Modify the $records to contain the rendered version of the field, not the raw $rendered = array(); @@ -49,6 +84,13 @@ class views_php_array_plugin_style_php_array extends views_plugin_style { $sets[$grouping][] = $row; } } + else if ($shallow) { + foreach ($rendered as $index => $row) { + $key = $row[$key_field]; + $value = $row[$value_field]; + $sets[$key] = $value; + } + } else { // Create a single group with an empty grouping field. $sets[''] = $rendered;