5

I'm having trouble getting the Views REST export to work nicely with multi-value fields. I have an image field that can have multiple images. I have added the field to my REST export View, however all values are being output on the same line. Like this:

[
    {
        "nid": "11",
        "image": "http://example.com/sites/default/files/2016-02/mobile-1.jpg\n,   http://example.com/sites/default/files/2016-02/mobile-2.jpg\n"
    }
]

What I would like to achieve is something like this:

[  
   {  
      "nid":"11",
      "image":{  
         "0":"http://example.com/sites/default/files/2016-02/mobile-1.jpg\n",
         "1":"http://example.com/sites/default/files/2016-02/mobile-2.jpg\n"
      }
   }
]

Is this possible? Perhaps using HOOK_views_pre_render() to change the returned value?

  • 1
    I think this happens because it's displaying in the same row for that field. Unfortunately when you uncheck this, it will make each image its own row so you'd end up with multiple items for each node. However if you use entity display styling, then you should be able to use display modes to control what fields you want. Of course then you lose the ability to add field aliases. – mradcliffe Feb 23 '16 at 15:09
  • @mradcliffe I guess this still isn't possible? – Marko Kunic Dec 23 '16 at 15:09
  • See below answer if it was reported as a bug. – mradcliffe Dec 27 '16 at 0:42
1

This looks like it's a plain bug. Please report it to the views.module issue queue in Drupal core: https://drupal.org/project/issues/drupal?component=views.module.

0

This happens even in 8.4, so I had to use the Views Field View plugin to create a view for just the list items (in your case, a list of image URLs) and add that view as a field to the main view. This works conceptually, but the output of the child view is littered with HTML which I can't seem to figure out a way to get rid of.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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