diff --git a/includes/plugins.inc b/includes/plugins.inc index bf09573..45fbd3d 100644 --- a/includes/plugins.inc +++ b/includes/plugins.inc @@ -183,6 +183,18 @@ function views_views_plugins() { 'type' => 'feed', 'help topic' => 'style-rss', ), + 'mapping' => array( + 'title' => t('Field mapping'), + 'help' => t('Maps specific fields to specific purposes.'), + 'handler' => 'views_plugin_style_mapping', + 'theme' => 'views_view', + 'uses row plugin' => FALSE, + 'uses fields' => TRUE, + 'uses options' => TRUE, + 'uses grouping' => FALSE, + 'type' => 'normal', + 'no ui' => TRUE, + ), ), 'row' => array( 'fields' => array( diff --git a/plugins/views_plugin_style_mapping.inc b/plugins/views_plugin_style_mapping.inc new file mode 100644 index 0000000..c8f3037 --- /dev/null +++ b/plugins/views_plugin_style_mapping.inc @@ -0,0 +1,85 @@ +define_mapping() as $key => $value) { + $options['views_field_mappings']['contains'][$key] = array( + 'default' => isset($value['default']) ? $value['default'] : '', + ); + } + + return $options; + } + + /** + * Overrides views_plugin_style::options_form(). + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + // Get the mapping. + $mapping = $this->define_mapping(); + + // Restrict the list of defaults to the mapping, in case they have changed. + $defaults = array_intersect_key($this->options['views_field_mappings'], $mapping); + + // Get the labels of the fields added to this display. + $field_labels = $this->display->handler->get_field_labels(); + + // For each mapping, add a select element to the form. + foreach($defaults as $key => $value) { + // If the field is optional, add a 'None' value to the top of the options. + $field_options = array(); + if ($optional = !empty($mapping[$key]['optional'])) { + $field_options = array('' => t('- None -')); + } + $field_options += $field_labels; + + $form['views_field_mappings'][$key] = array( + '#type' => 'select', + '#options' => $field_options, + '#title' => $mapping[$key]['label'], + '#default_value' => $defaults[$key], + '#required' => !$optional, + ); + + // Add a description if one is provided. + if (!empty($mapping[$key]['description'])) { + $form['views_field_mappings'][$key]['#description'] = $mapping[$key]['description']; + } + } + } + +} diff --git a/views.info b/views.info index c0d8f14..29e7eaf 100644 --- a/views.info +++ b/views.info @@ -242,6 +242,7 @@ files[] = plugins/views_plugin_style_default.inc files[] = plugins/views_plugin_style_grid.inc files[] = plugins/views_plugin_style_list.inc files[] = plugins/views_plugin_style_jump_menu.inc +files[] = plugins/views_plugin_style_mapping.inc files[] = plugins/views_plugin_style_rss.inc files[] = plugins/views_plugin_style_summary.inc files[] = plugins/views_plugin_style_summary_jump_menu.inc