diff --git a/content_taxonomy.module b/content_taxonomy.module index 08982d58cb6b6bba1e07afdee598cc4d8c598678..6832b72c3d2670c94b8a51bb1380cb63895d8c56 100644 --- a/content_taxonomy.module +++ b/content_taxonomy.module @@ -135,10 +135,11 @@ function content_taxonomy_field_settings($op, $field) { // Add a relation to the taxonomy term table. $data[$table_alias][$field['field_name'] .'_value']['relationship'] = array( - 'handler' => 'views_handler_relationship', + 'handler' => 'content_taxonomy_handler_relationship', 'base' => 'term_data', 'field' => 'tid', 'label' => t('@field-title term', array('@field-title' => check_plain(t($field['widget']['label'])))), + 'content_field_name' => $field['field_name'], ); // Swap the filter handler to the 'in' operator. diff --git a/includes/views/content_taxonomy.views.inc b/includes/views/content_taxonomy.views.inc index 81b12b0e581f4e1a708dc998562582463c9e5ffc..07a49b30df6646631f8bad5593c10a124bd43406 100644 --- a/includes/views/content_taxonomy.views.inc +++ b/includes/views/content_taxonomy.views.inc @@ -12,6 +12,9 @@ function content_taxonomy_views_handlers() { 'content_taxonomy_handler_filter_many_to_one' => array( 'parent' => 'content_handler_filter_many_to_one', ), + 'content_taxonomy_handler_relationship' => array( + 'parent' => 'views_handler_relationship', + ), ), ); } diff --git a/includes/views/content_taxonomy_handler_relationship.inc b/includes/views/content_taxonomy_handler_relationship.inc new file mode 100644 index 0000000000000000000000000000000000000000..a09b93b996ce65c7291b9db0e5542101b607b85a --- /dev/null +++ b/includes/views/content_taxonomy_handler_relationship.inc @@ -0,0 +1,72 @@ +content_field = content_fields($this->definition['content_field_name']); + } + + function option_definition() { + $options = parent::option_definition(); + $options['delta'] = array('default' => -1); + + return $options; + } + + /** + * Add a delta selector for multiple fields. + */ + function options_form(&$form, &$form_state) { + $field = $this->content_field; + parent::options_form($form, $form_state); + + // Only add the form gadget if the field is multiple. + if ($field['multiple']) { + $max_delta = $field['multiple']; + // 1 means unlimited. + if ($max_delta == 1) { + $max_delta = 10; + } + + $options = array('-1' => t('All')); + for ($i = 0; $i < $max_delta; $i++) { + $options[$i] = $i + 1; + } + $form['delta'] = array( + '#type' => 'select', + '#options' => $options, + '#default_value' => $this->options['delta'], + '#title' => t('Delta'), + '#description' => t('The delta allows you to select which item in a multiple value field to key the relationship off of. Select "1" to use the first item, "2" for the second item, and so on. If you select "All", each item in the field will create a new row, which may appear to cause duplicates.'), + ); + } + } + + function ensure_my_table() { + if (!isset($this->table_alias)) { + $join = $this->get_join(); + if (!isset($join->extra)) { + $join->extra = array(); + } + $delta = isset($this->options['delta']) ? $this->options['delta'] : -1; + if ($delta != -1) { + $join->extra[] = array( + 'field' => 'delta', + 'value' => $delta, + 'numeric' => TRUE, + ); + } + + $this->table_alias = $this->query->add_table($this->table, $this->relationship, $join); + } + return $this->table_alias; + } +} \ No newline at end of file