0

Summary: Duplicate items in view where there are paragraph fields.

I've dug through everywhere trying to find a solution to this. I found a very long bug report about it and tried the patch. Even though it patched correctly, the issue was still not fixed. I've tried distinct, aggregation, etc. There's a lot of complaints on there about it not working, so I'm not the only one.

The view I'm working on is for a blog. It has the title, thumbnail of image, body, and read more link. The image and body are both paragraph fields. As such, I get two listings for every blog entry: one with the image, one with the body. I've attached an example as well as a screenshot of my view settings.

Has anyone found a way to get this fixed?

Edit: Here is the bug report: https://www.drupal.org/project/drupal/issues/2993688

blog settings

blog listing

10
  • What you are trying to do here will not work, due the way SQL works. It might not be what you want, but this is technically working as intented and not even a Paragraph bug: every 1 node has a relation to 2 paragraphs, which always will result in 2 rows in SQL.
    – Hudri
    Commented Sep 3 at 8:08
  • You might try something like "Multiple field settings: display all values in the same row" (you've got 1 paragraph field on the node, collect all paragraph "values" into the same row). This often works with taxonomy terms (complete entities), but I'm not so sure if this works with individual subfields of Paragraphs.
    – Hudri
    Commented Sep 3 at 8:15
  • 3
    I might be missing something, but can’t you just render the paragraph in a certain view mode instead, then arrange the fields in that view mode to suit?
    – Clive
    Commented Sep 3 at 10:12
  • 3
    It would be helpful to this community if you would link to the very long bug report you referenced.
    – mona lisa
    Commented Sep 3 at 15:47
  • 2
    Maybe try backwards. Create a view of paragraph and add relationship to content/node.
    – No Sssweat
    Commented Sep 5 at 20:18

1 Answer 1

0
+50

While this is not a direct solution for your question, it is how I work around these types of problems. It can get complicated in a hurry (and cause all sorts of maintenance headaches!) when you try to do too much in a single view display's configuration.

Suggestion:

  1. Ask this view to just do one thing: render blog posts, ideally via a specific view mode.
    • I.e. drop the relationship and move whatever image and text gathering logic you require to the blog post view mode.
  2. Configure the blog post view mode how you need it. For example, in the configuration for that view mode, render the title, field_add_sections (the field that seems to contain your image and text paragraphs), and a read more link.

I think the major complicating factor here is something that is not explicitly stated in your question, I think you might have multiple paragraphs referenced in field_add_sections, but you only want to show the content of two of them. If that's the case, you could limit the output of that field to show only the required paragraphs in a number of ways. For example, you might try:

  • the formatter provided by the View Entity Reference Field Formatter plus a view display to show only the relevant paragraphs from your paragraphs field. (Though you may need the patch from Issue #3447480) (Disclaimer: I've never used this module, but it sounds like it might help here! :shrug:)
  • the Etools module has a field formatter to limit the output of a paragraphs field to only the first X paragraphs of a specific bundle or bundles. For example, you could configure it to output only the first 2 paragraphs that are either image or text paragraphs. (Disclaimer: this is a small module that I authored. You may prefer to create a custom formatter instead. If that's the case, take a look at the ERRSubsetFormatter and the EntityReferenceSubsetTrait for a headstart on the logic.)
  • a custom field formatter with your own logic or mimicking the approach of the two options listed above.

If you do not want to use a view mode for whatever reason, this approach still works with some modification:

  1. Continue rendering fields in your view like you are now.
  2. Remove the relationship from the view.
  3. Remove your current image and text fields and render the field_add_sections field in the view display and apply your magic field formatter (like those suggested above) to the field right here in this view.

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.