2

In my Drupal 7 project I have users of role A and B respectively. Users of role A can create content and users of role B can flag it.

I'm building a view that displays on A users' account page their content and names of B users who flaggd it.

I have created a view Content (not User) and added relationship Flags: Content flag and consequently field Flags: User uid to display together with content related fields.

In view block I use Grid format. Same content information is displayed several times per each user who flagged it, like bellow

Content title QWERTY
Users uid who flagged 1

Content title QWERTY
Users uid who flagged 2

Content title QWERTY
Users uid who flagged 3

How can I display content information only once and users who flagged in one field separated by comma?

1 Answer 1

0

you need to edit /drupal/sites/all/themes/MYTHEMENAME/template.php

then add the following code.

function MYTHEMENAME_preprocess_views_view_fields($vars){
      if ($vars['view']->name == "VIEWNAME" && $vars['view']->current_display == "DISPLAY" && $vars['id'] != 1){
        $vars['fields']['title']->content = '';
      }
    }

What this code is saying is if your row is not equal to (!=) 1, then don't display anything. Thus, it will print your title only for row 1.

  • replace MYTHEMENAME with your actual theme name.

  • replace VIEWNAME with your view's name. example: flagged_content

  • replace DISPLAY with your view's machine name. You can find this by editing your view, then under Advanced -> other

    examples: block, block_1, page, page_1 or default. It's default if you're using your master view.

For user's separated by comma you would have to use css for that.

JS FIDDLE EXAMPLE

PS: I think you would have to change it from grid to html list for your view.

Your Answer

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

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