Hi,

I am using CCK 6.x-3.x-dev and Views 6.x-2.8 and I am trying to show CCK Multigroup content correctly in Views. Currently, when a user types in content

Group 1
Label A: Text 1A
Label B: Text 1B
Group 2
Label A: Text 2A
Label B: Text 2B

Views generates:

Label A: Text 1A Text 2A
Label B: Text 1B Text 2B

Correct display should be:

Label A: Text 1A
Label B: Text 1B

Label A: Text 2A
Label B: Text 2B

How do I achieve that? I see that there are _delta fields and "Content multigroup" filter in Vews but have no idea what they do. I also saw a thread that seems to have the answer for me http://drupal.org/node/416154 but it was posted since March 2009 and very confusing...Can someone please help?

Many thanks!!

BB

Comments

someone please help?

anyone?

looking forward to an update on this too

Category:task» support
Status:Active» Fixed

The filter under the "Content multigroup" group in Views UI is aimed to allow you to sync the delta values of fields in a multigroup. Though, if you mix non-multigroup and multigroup fields, you'll get duplicate rows, just like when you mix multiple value fields. The multigroup does not have a grouping checkbox. Instead, I think you may try using Views Custom Field module, with some PHP code you can render a multigroup. See fieldgroup_view_group() function in fieldgroup.module.

markus_petrux,

Thanks for your reply. I appreciate your help but I still dont understand how to get this done...do you know if there's any step by step tutorial/forum thread that may help? Thanks again.

BB

One possible solution is:

  • Choose fields with option group multiple fields and hide fields
  • Install Views Custom field
  • Choose php and enter code to check out variables:
    <?php
    print_r
    ($data);
    ?>
  • Write a script to print whatever you want to print. Example:
    <?php
    //print_r($data);
    foreach ($data->node_data_field_titel_field_titel_value as $key => $linktitle) {
    $link = $data->node_data_field_titel_field_titel_value[$key][value];
    $link = '<div><a href ="'.$data->node_data_field_url_field_url_value[$key][value].'">'.$link.'</a></div>';
    print
    $link;
    }
    ?>

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Status:Closed (fixed)» Active

hi blueblade, which solution did work out for you?

I gave it up completely - not using multigroup at all.

Instead, I created new a content type to collect information I originally wanted to have in multigroup, then use Views to add links to those content once users submit their information. These links show up on where multigroup information was originally supposed to be instead, which means to view the info details, you will have to click on those links and navigate to a new page. In multigroup, you can limit how many repeats for the multigroups, for this, I use Node Limit Number module instead to set a limit to how many times each user can create that new content type.

By doing it this way I can actually get the users to submit even more information since I can add as many cck fields to the new content type, everything is more flexible too.

Hope this help.

Perhaps this view-code will help you or someone else
i'ts from my upcoming label page.

i have this content-types:

RELEASE
- nid
- title
- multigroup "tracks"
- - Pos
- - NodeReference->Tracks

TRACKS
- nid
- titel
- audio
- further info

So one Release can have unlimited Tracks:

e.g.

Release: a very cool cd
consists of:
Pos | Track
A1 | Song
A2 | Song Remix
B1 | Lalala
B2 | Cool Music

i like to have a view called from a panel via argument "nid"

it works fine with this view now .... after many many ...many tries ;)

$view = new view;
$view->name = 'tracks_by_release';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Standards', 'default');
$handler->override_option('relationships', array(
  'field_releasetracks_nid' => array(
    'label' => 'Tracks',
    'required' => 0,
    'delta' => '-1',
    'id' => 'field_releasetracks_nid',
    'table' => 'node_data_field_releasetracks',
    'field' => 'field_releasetracks_nid',
    'relationship' => 'none',
  ),
));
$handler->override_option('fields', array(
  'field_release_trackpos_value' => array(
    'label' => 'Pos',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'widget',
    'format' => 'default',
    'multiple' => array(
      'group' => 0,
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_reversed' => 0,
    ),
    'exclude' => 0,
    'id' => 'field_release_trackpos_value',
    'table' => 'node_data_field_release_trackpos',
    'field' => 'field_release_trackpos_value',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Übersteuern',
    ),
  ),
  'title' => array(
    'label' => 'Beiträge',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'field_releasetracks_nid',
  ),
  'delta' => array(
    'label' => 'Pos (field_release_trackpos) - delta',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'set_precision' => FALSE,
    'precision' => 0,
    'decimal' => '.',
    'separator' => ',',
    'prefix' => '',
    'suffix' => '',
    'exclude' => 0,
    'id' => 'delta',
    'table' => 'node_data_field_release_trackpos',
    'field' => 'delta',
    'override' => array(
      'button' => 'Übersteuern',
    ),
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'nid' => array(
    'default_action' => 'ignore',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'Alle',
    'title' => 'track',
    'breadcrumb' => '',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'node',
    'validate_fail' => 'not found',
    'break_phrase' => 0,
    'not' => 0,
    'id' => 'nid',
    'table' => 'node',
    'field' => 'nid',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
      '3' => 0,
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_fixed' => '',
    'default_argument_user' => 0,
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'release' => 'release',
      'blog' => 0,
      'poll' => 0,
      'station_album' => 0,
      'station_playlist' => 0,
      'station_program' => 0,
      'station_schedule' => 0,
      'panel' => 0,
      'artists' => 0,
      'event' => 0,
      'location' => 0,
      'music_track' => 0,
      'page' => 0,
      'profile' => 0,
      'story' => 0,
      'user_profile_team' => 0,
    ),
    'validate_argument_node_access' => 1,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '1' => 0,
      '5' => 0,
      '4' => 0,
      '3' => 0,
      '6' => 0,
      '2' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_node_flag_name' => '*relationship*',
    'validate_argument_node_flag_test' => 'flaggable',
    'validate_argument_node_flag_id_type' => 'id',
    'validate_argument_user_flag_name' => '*relationship*',
    'validate_argument_user_flag_test' => 'flaggable',
    'validate_argument_user_flag_id_type' => 'id',
    'validate_argument_php' => '',
  ),
));
$handler->override_option('filters', array(
  'multigroup_release_group_release_mgroup_tracks' => array(
    'operator' => '=',
    'value' => '',
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'content_multigroup_master_field' => 'node_data_field_releasetracks',
    'id' => 'multigroup_release_group_release_mgroup_tracks',
    'table' => 'node',
    'field' => 'multigroup_release_group_release_mgroup_tracks',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Übersteuern',
    ),
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('items_per_page', 0);
$handler->override_option('distinct', 0);
$handler = $view->new_display('block', 'Tracks by Release (Table)', 'block_1');
$handler->override_option('style_plugin', 'table');
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);

So is this just never going to happen or are there plans for it?

I am using a dirty hack to show this in the way I like.

The method consist of two parts:

  • a function in template.php
  • some code in the views-view-fields--myview.tpl.php

The template.php function

In this function we combine the fields in different elements of the multigroup into one pipe separated value.

function theme_content_view_multiple_field($items, $field, $values) {
  # Insert in the following two arrays all the fields that you want to have this behavior
  $not_default = array( 'field_label_a', 'field_label_b' );
  $pipe_sep = array( 'field_label_a', 'field_label_b' );
  if (!in_array($field['field_name'], $not_default)) {
    // If this is not my tuned field, then use original theme function directly.
    return theme_content_view_multiple_field($items, $field, $values);
  }
  if (in_array($field['field_name'], $pipe_sep)) {
    $array = array();
    foreach ($items as $item) {
      if (!empty($item) || $item == '0') {
        $array[] = $item;
      }
    }
    return implode('|',$array);
  }
  // Separate item values with my favorite separator.
  $separator = ', ';
  $array = array();
  foreach ($items as $item) {
    if (!empty($item) || $item == '0') {
      $array[] = $item;
    }
  }
  return implode($separator, $array);
}

The views-view-fields--myview.tpl.php code

Here we receive the output of the previous function, transform it into an array and operate with it.

if ($fields['field_label_a_value']->content):
  $label_a = explode('|', $fields['field_label_a_value']->content);
  $label_b = explode('|', $fields['field_label_b_value']->content);
  /**
   * Constructing an array of objects
   * Each object is a <strong>group</strong>
   * Each group has all the fields you are using
  */
  foreach($label_a as $k => $v):
    $item = new stdClass();
    $item->label_a = $v;
    $item->label_b = $label_b[$k];
    $items[] = $item;
  endforeach;
endif;
/**
* Printing the array of objects as an unordered list
* Each element of the list is a <strong>group</strong>
*/
if (count($items)):
  print '<ul class="items">';
  foreach($items as $v):
    print '<li class="a-given-item">';
      foreach($v as $k => $vv):
        if ($vv!='')
          print '<span class="'.$k.'">'.$vv.'</span> ';
      endforeach;
    print '</li>';
  endforeach;
  print '</ul>';
endif;

I know that this is probably the dirtiest hack ever… but so far, it seems to be working. Also, by writing this I recognize several ways of improving this code. Maybe I'll do it and post an update.

Subscribing.
Is there any way to solve an issue: show in Views 3 dev multigroup fields separately ?
For now i able to show only all multifroup, the struscture is follows:

bmw - yellow
audi - black
audi - green

but i want to have handler to separate values, for example to show only second value from group (audi - black) + filter to select values by first and second - select from multigroup only audi cars with colors,
or only choosen color cars

please point me on the solution

funkytraffic, this helped me out a great deal!

thanks for drawing my attention to Views Custom Field, this is an arbitrarily powerful module for displaying data just the way that you want.

exactly what you need to get Multigroup playing nicely with views.

The Multigroup Views Filter feature wasn't working for me until I downgraded to PHP 5.2 (from PHP 5.3). It is now working fabulously.

For newbs, your PHP version information is available at /admin/reports/status .

Status:Active» Fixed

The original support request was answered. This issue is veering off into other questions/issues.

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Just wanted to chime in with the solution to show multi group values along with any other values in a node with out the duplication of non-multi group values.

Do the following:
all the fields in the multigroup need the box checked: Group multiple values

'Distinct' under basic settings, enable 'Distinct' .

Easiest way to see your results is in a table view.

Thats it!

I've just had a massive problem which has been fixed by NOT following arkjoseph. (sorry)

Do NOT Group Multiple Values for any fields
AND Do NOT select Distinct.

Have JUST multigroup fields under 'Fields'
Select the Content multigroup: content under 'FIlters'
Then select your arguments (Node ID etc)
Style: Table also looks good.

Hope this helps

Tried this way with latest cck dev, and got a:
Fatal error: Call to undefined method stdClass::join() in /var/www/drupal/sites/all/modules/views/includes/query.inc on line 926

#18 arkjoseph Thanks a lot
It works perfect

#19 matteblacke's method also work - thanks :)

#19 matteblack's method also has the added bonus of printing each value in the multigroup on a separate row in a table (allowing striped even/odd rows), and sorting the multigroup by one of its fields. Sweet.

#19 in combination with views_field_view works great!