1

I have a content type with a multivalue entity reference field. In a view I show a list of nodes of this content type in a table. The column of the multivalue field (column C in the example) should show a comma seperated list of a field of the content type it references, these values are just single letters. In the view I enabled 'Display all values in the same row' for the multivalue field. Aggregation is on and the group column is set to Entity ID.

So for example, this should be the output of the view:

Column A     Column B      Column C
--------     --------      --------
value A1     value B1      X, Y, Z
value A2     value B2      Y, Z

When actually I get this:

Column A     Column B      Column C
--------     --------      --------
value A1     value B1      X, X, X
value A2     value B2      Y, Y

So what happens is, the first value in the list gets repeated as many times as the number of values.

I appreciate any help I can get!

This is the export of my view:

$view = new view();
$view->name = 'view_constitutionele_genetische_aandoeningen';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Constitutionele genetische aandoeningen';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Constitutionele genetische aandoeningen';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['group_by'] = TRUE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['distinct'] = TRUE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '50';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'field_gentest_accreditatie' => 'field_gentest_accreditatie',
  'title' => 'title',
  'field_gentest_gen_locus_chromos' => 'field_gentest_gen_locus_chromos',
  'field_mat_gentest_afkorting' => 'field_mat_gentest_afkorting',
  'field_gentest_materiaal' => 'field_gentest_materiaal',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'field_gentest_accreditatie' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'title' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'field_gentest_gen_locus_chromos' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'field_mat_gentest_afkorting' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'field_gentest_materiaal' => array(
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
);
/* Relationship: Entity Reference: Referenced Entity */
$handler->display->display_options['relationships']['field_gentest_materiaal_target_id']['id'] = 'field_gentest_materiaal_target_id';
$handler->display->display_options['relationships']['field_gentest_materiaal_target_id']['table'] = 'field_data_field_gentest_materiaal';
$handler->display->display_options['relationships']['field_gentest_materiaal_target_id']['field'] = 'field_gentest_materiaal_target_id';
/* Field: Content: Accreditatie */
$handler->display->display_options['fields']['field_gentest_accreditatie']['id'] = 'field_gentest_accreditatie';
$handler->display->display_options['fields']['field_gentest_accreditatie']['table'] = 'field_data_field_gentest_accreditatie';
$handler->display->display_options['fields']['field_gentest_accreditatie']['field'] = 'field_gentest_accreditatie';
$handler->display->display_options['fields']['field_gentest_accreditatie']['label'] = '';
$handler->display->display_options['fields']['field_gentest_accreditatie']['element_label_colon'] = FALSE;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = 'Aandoening';
$handler->display->display_options['fields']['title']['alter']['make_link'] = TRUE;
$handler->display->display_options['fields']['title']['alter']['rel'] = 'width:600,height:400';
$handler->display->display_options['fields']['title']['alter']['link_class'] = 'mb';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
$handler->display->display_options['fields']['title']['element_label_colon'] = FALSE;
/* Field: Content: Gen / Locus / Chromosoom */
$handler->display->display_options['fields']['field_gentest_gen_locus_chromos']['id'] = 'field_gentest_gen_locus_chromos';
$handler->display->display_options['fields']['field_gentest_gen_locus_chromos']['table'] = 'field_data_field_gentest_gen_locus_chromos';
$handler->display->display_options['fields']['field_gentest_gen_locus_chromos']['field'] = 'field_gentest_gen_locus_chromos';
$handler->display->display_options['fields']['field_gentest_gen_locus_chromos']['element_label_colon'] = FALSE;
/* Field: Content: Afkorting */
$handler->display->display_options['fields']['field_mat_gentest_afkorting']['id'] = 'field_mat_gentest_afkorting';
$handler->display->display_options['fields']['field_mat_gentest_afkorting']['table'] = 'field_data_field_mat_gentest_afkorting';
$handler->display->display_options['fields']['field_mat_gentest_afkorting']['field'] = 'field_mat_gentest_afkorting';
$handler->display->display_options['fields']['field_mat_gentest_afkorting']['relationship'] = 'field_gentest_materiaal_target_id';
$handler->display->display_options['fields']['field_mat_gentest_afkorting']['label'] = '';
$handler->display->display_options['fields']['field_mat_gentest_afkorting']['exclude'] = TRUE;
$handler->display->display_options['fields']['field_mat_gentest_afkorting']['element_label_colon'] = FALSE;
/* Field: Content: Materiaal */
$handler->display->display_options['fields']['field_gentest_materiaal']['id'] = 'field_gentest_materiaal';
$handler->display->display_options['fields']['field_gentest_materiaal']['table'] = 'field_data_field_gentest_materiaal';
$handler->display->display_options['fields']['field_gentest_materiaal']['field'] = 'field_gentest_materiaal';
$handler->display->display_options['fields']['field_gentest_materiaal']['alter']['alter_text'] = TRUE;
$handler->display->display_options['fields']['field_gentest_materiaal']['alter']['text'] = '[field_mat_gentest_afkorting]';
$handler->display->display_options['fields']['field_gentest_materiaal']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_gentest_materiaal']['settings'] = array(
  'link' => 1,
);
$handler->display->display_options['fields']['field_gentest_materiaal']['group_column'] = 'entity_id';
$handler->display->display_options['fields']['field_gentest_materiaal']['delta_offset'] = '0';
/* Field: Content: Duur */
$handler->display->display_options['fields']['field_gentest_duur']['id'] = 'field_gentest_duur';
$handler->display->display_options['fields']['field_gentest_duur']['table'] = 'field_data_field_gentest_duur';
$handler->display->display_options['fields']['field_gentest_duur']['field'] = 'field_gentest_duur';
$handler->display->display_options['fields']['field_gentest_duur']['element_label_colon'] = FALSE;
/* Sort criterion: Content revision: Title */
$handler->display->display_options['sorts']['title']['id'] = 'title';
$handler->display->display_options['sorts']['title']['table'] = 'node_revision';
$handler->display->display_options['sorts']['title']['field'] = 'title';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'gentest' => 'gentest',
);
$handler->display->display_options['filters']['type']['group'] = 1;
/* Filter criterion: Content: Title */
$handler->display->display_options['filters']['title']['id'] = 'title';
$handler->display->display_options['filters']['title']['table'] = 'node';
$handler->display->display_options['filters']['title']['field'] = 'title';
$handler->display->display_options['filters']['title']['operator'] = 'contains';
$handler->display->display_options['filters']['title']['exposed'] = TRUE;
$handler->display->display_options['filters']['title']['expose']['operator_id'] = 'title_op';
$handler->display->display_options['filters']['title']['expose']['label'] = 'Zoeken';
$handler->display->display_options['filters']['title']['expose']['operator'] = 'title_op';
$handler->display->display_options['filters']['title']['expose']['identifier'] = 'title';
$handler->display->display_options['filters']['title']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
);
/* Filter criterion: Content: Language */
$handler->display->display_options['filters']['language']['id'] = 'language';
$handler->display->display_options['filters']['language']['table'] = 'node';
$handler->display->display_options['filters']['language']['field'] = 'language';
$handler->display->display_options['filters']['language']['value'] = array(
  'all' => 'all',
  '***CURRENT_LANGUAGE***' => '***CURRENT_LANGUAGE***',
  '***DEFAULT_LANGUAGE***' => '***DEFAULT_LANGUAGE***',
  'und' => 'und',
  'nl' => 'nl',
  'en' => 'en',
  'fr' => 'fr',
);
/* Filter criterion: Content: Type (field_gentest_type) */
$handler->display->display_options['filters']['field_gentest_type_tid']['id'] = 'field_gentest_type_tid';
$handler->display->display_options['filters']['field_gentest_type_tid']['table'] = 'field_data_field_gentest_type';
$handler->display->display_options['filters']['field_gentest_type_tid']['field'] = 'field_gentest_type_tid';
$handler->display->display_options['filters']['field_gentest_type_tid']['value'] = array(
  0 => '389',
);
$handler->display->display_options['filters']['field_gentest_type_tid']['vocabulary'] = 'taxonomy_categorie_gentest';

/* Display: Block */
$handler = $view->new_display('block', 'Block', 'view_block_const_gen_aan');
$handler->display->display_options['block_description'] = 'View Bloc: Const gen aan';
2
  • Did you try to set distinct and aggregation? You said that you use "Aggregation" but I haven't noticed it in the view export
    – milkovsky
    Commented Jul 24, 2013 at 13:54
  • My bad, I must have exported the view right after I turned aggregation and/or distinct off just to see if it would make a difference. I updated the view export now. Thanks you for having a look.
    – Smos
    Commented Jul 24, 2013 at 14:36

2 Answers 2

2

Views cannot remove certain duplications in multivalue fields, however, you can remove them using theme pre-rendering. This has been discussed at: https://drupal.org/node/1223448

Some variation of this might help you (in mytheme/template.php):

<?php
/*
* implements hook_view_pre_render()
*/
function mytheme_views_pre_render(&$view)
{
  switch($view->name)
  {
    case 'no_double_nodes_view':
      $nids = array(); // array of nodes to prevent duplicates
      $resultNoDoubleNodes = array(); // manipulated results
      foreach($view->result as $key => $result) // check each node of the result array on it's nid
      {
        $nid = $result->nid;
        if (!in_array($nid, $nids)) // if this node isn't a duplicate
        {
          $resultNoDoubleNodes[] = $view->result[$key]; // add it to the manipulated results
          $nids[$key] = $nid; // mark this nid as in results to prevent duplicates from now on
        };
      }
      $view->result = $resultNoDoubleNodes; // replace the old results with the results without duplicates
      break;
    default:
      break;
  }
}
?>
3
  • Thank you for responding! I implement the view in my page by using this piece of code in the code template: $block = module_invoke('views', 'block_view', 'fee7c29e58dcf4a8033b088318da88b5'); print render($block['content']); Is the page template getting rendered after the template function _views_pre_render perhaps? Because when I print out the $view variable I don't see my view in there.
    – Smos
    Commented Jul 25, 2013 at 10:37
  • Smos, I suggest checking the results of your view as a normal page first , to make sure you've removed the duplicates. Then output it as a block, in case your output method is causing you problems. Commented Aug 11, 2015 at 19:34
  • I had a similar situation to Smos, and this solution resolved it. Commented Aug 11, 2015 at 19:37
0

If your quest is just to hide the Duplicate Row from the table then jQuery is your friend in Drupal 7. I had same issue of duplicate rows, I hide it using:

// Hiding the duplicate rows from views table.
        var seen = {};
        jQuery('.view-name table tbody tr').each(function() {
            var txt = jQuery(this).text();
            if (seen[txt])
                jQuery(this).remove();
            else
                seen[txt] = true;
        });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.