Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm currently trying to make a json flow from my server but cant print images inside a node.
This is the output ive managed to get:
node1
images - "img1",
node1
images - "img2",
----------------------And this:(stripped-tags)
node1
images - ",",
Tried every combo with views - format settings and field settings but still isn't working.
Anyone has the same problem?
Im using:
Views 7.x-1.x-dev 7.x-3.0-rc1
Views-json 7.x-1.x-dev
NOTE: forgot to mention that its a array from a node with multiple values in one field
Comment | File | Size | Author |
---|---|---|---|
#26 | multi_value_images_with_embedded_image_fix-1319714-26.patch | 5.36 KB | jaymallison |
#25 | multi_value_images_with_embedded_image_fix-1319714-25.patch | 4.01 KB | jaymallison |
#24 | multi_value_images-1319714-24.patch | 2.73 KB | jaymallison |
#23 | 452px-YardOfAle.jpg | 65.63 KB | bisonbleu |
#14 | configure field modal.JPG | 75.92 KB | Alexander Allen |
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedsorry for double post... delete this...
Comment #2
Anonymous (not verified) CreditAttribution: Anonymous commented*delete*
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commented*delete*
Comment #4
Pasqualledo you have multiple images in one node in one field?
Comment #5
Anonymous (not verified) CreditAttribution: Anonymous commentedYes I do, forgot to mention that.
Comment #6
PieterDCDoes anyone know if this works with Views 2?
The code says it's compatible but Views API 2.0. I'm astonished it works that well with Views 3. But I'm experiencing the same problem as @Psyd; multivalue fields always get reduced to just 1 field.
Comment #7
francismacomber CreditAttribution: francismacomber commentedI had the same problem. I was only getting one image of my multi-image field. Here's my quick fix:
Drupal 7.10
Views: 7.x-3.0-rc3
Views JSON: 7.x-1.x-dev
It's in "views_json.module" at line 140:
Comment #8
KimmoT CreditAttribution: KimmoT commentedI got mine to work by using preg_match_all instead of preg_match in the else part where we are looking for image tags. In my case I simply had to turn the values into a JSON list.
Comment #9
PasqualleComment #10
Anonymous (not verified) CreditAttribution: Anonymous commentedAlright, im gonna test this soon as I have time.
Thanks everybody for your support.
Comment #11
philippsimon.de CreditAttribution: philippsimon.de commentedi optimized the code a bit.
i also tried to include the alt text of the images but sadly views_json doesn't accept a construct like this:
$field_output[$i] = array( "src" => "http....", "alt" => "alt text" );
it would be nice to have also the alt and the title text.
Comment #12
eusonic CreditAttribution: eusonic commentedI found a simple work around for this using the Image URL Formatter module. Simply switch the image field's formatter to "Image URL." This will output a comma separated list of urls, bypassing the troublesome code posted in comment #7. Plus, you can still use image styles.
Comment #13
xandeadx CreditAttribution: xandeadx commented#12 work for me
Comment #14
Alexander Allen CreditAttribution: Alexander Allen commentedFYI, as an alternative to comment #12 (but not to discredit it), I am also currently able to output images that reside in multiple-value fields using the field_collection module: http://drupal.org/project/field_collection.
When I am editing a View, inside the "Configure Field" modal for field_collection fields I can choose whether to display the fields in one or multiple lines. Currently I have my field_collection field setup to display in multiple lines - see attached JSON output.
I must admit though, that I do not like a bit that we are doing a
preg_match()
on field contents to search for<img>
tags. Not only it seems not scalable (we are doing a regex on every field, on every single row), it just seems cruft[y] overall. I vote for finding a more elegant way to determine if a field is of type image. Maintainers, please let me know if you feel we should leave it as is or have your mind set on a solution already. I'm going to see if I can roll something out this weekend. Will post a patch first since it might be a big change.Comment #15
Alexander Allen CreditAttribution: Alexander Allen commentedI had the wrong assumption that field_collection was giving the ability to control whether to display multiple items in one views field or not. Field collection is just used for grouping multiple fields in one unit... oops.
After creating a separate and clean baseline site without using the field_collection module I figured out that what we want to do is actually be able to check "Display all values in the same row" and return a JSON collection...
Comment #16
eusonic CreditAttribution: eusonic commentedAlexander,
The problem with unchecking "Display all values in the same row" is that it will create duplicates of all the single-value fields, since the entire row is getting repeated. If you have more than one multi-value field the problem is compounded. This can create some seriously bloated JSON. (Believe me, I've been down this road...)
Using Field Collection is an interesting idea. It would be an amazing solution if we could get a nested structure. Something like this:
I don't think this is currently possible. Anyone know?
Comment #17
kerberos CreditAttribution: kerberos commentedThe patch in #11 works well for images. Thanks!
-Daniel
Highline Residential Brokerage
Comment #18
Alexander Allen CreditAttribution: Alexander Allen commentedI am currently working in a generic solution for all views_datasource plugins. The solution will allow for multi-fields, as well for module developers to extend our rendering process without having to fork or patch the module. Since the change involves major restructuring, I'm going to start committing my changes to my views_datasource sandbox. That way it will be easier for people to test the new code. As soon as I have a writeup I shall post it into a general issue, since this rewrite will solve other issues as well. Stay tuned.
Comment #19
Alexander Allen CreditAttribution: Alexander Allen commentedTagging.
For those following this issue, I've created issue #1699368: #RVDA: Rewrite Views Datasource's Architecture, which will eventually incorporate a fix for this issue, no ETA. This issue is now a dependency of #1699368.
Comment #20
Alexander Allen CreditAttribution: Alexander Allen commentedComment #21
cbrasfield CreditAttribution: cbrasfield commentedI created a separate issue for multiple values not being displayed that are not image specific. http://drupal.org/node/1881670
Comment #22
juliusvaart CreditAttribution: juliusvaart commentedI can confirm the patch in #11 is also working on views.xml.module (it starts on line 134).
Kind regards,
Julius
Comment #23
bisonbleu CreditAttribution: bisonbleu commentedI've been battling this issue for 2 days and #12 is by far the simplest and most accessible fix. @eusonic, I owe you 1 yard of beer! : )
Comment #23.0
bisonbleu CreditAttribution: bisonbleu commented(unnecessary edit)
Comment #24
jaymallison CreditAttribution: jaymallison commentedI've made a patch for this. I still think this whole implementation needs to be refactored to handle images without regex, but this is useful enough now that I thought I should contribute it back.
It incorporates changes from #11 as well as my own changes that add multi-ordinal support to add the alt tag contents as well. This required a modification to views_views_json_style.theme.inc to add support for that.
Hope someone finds this useful. I myself am using it to expose JSON from Drupal to a pure Angular JS frontend.
Comment #25
jaymallison CreditAttribution: jaymallison commentedAfter reviewing this issue: https://drupal.org/node/913668
I decided to re-roll this with the fixes from the RTBC patch in comment #25 posted over there. The code is intertwined so it's important that these two play nice.
Comment #26
jaymallison CreditAttribution: jaymallison commentedOne more time with some more tweaks to make the src/alt approach work right with single images
Comment #27
Jibus CreditAttribution: Jibus commented#26 works for me on a json feed.
Got a couple of errors when applying the patch
Thanks !
Comment #28
chrsnlsn CreditAttribution: chrsnlsn commentedis this patch supposed to make a multi image field work correctly?
I have a multiple image field and it's still only putting one image in the json output.
Comment #29
japerryMarking fixed, I've cleaned up the code a bit and committed #26. If there are further issues we can open new issues or re-open this.
Comment #32
cscott5288 CreditAttribution: cscott5288 commentedI have a multi-field collection which allows multi-images and I am unable to correctly output JSON with the latest dev release.
Comment #33
liquidcms CreditAttribution: liquidcms commentedIs this actually fixed? If so what is the trick to getting it working?
I have a multi entityref field (tabs) which leads to multiple values settings option for that view field. if i display in single row with comma separator i get json that looks like this:
as i would sort of expect i get a CSV list of nids, which when json decoded returns NULL. is there a format setting which maps this to a json array?
Comment #34
kenorb CreditAttribution: kenorb commentedCreate a new ticket then if you think it's still the problem, with more details.
Comment #35
Vikash raj CreditAttribution: Vikash raj commentedcan it be possible to do rest export of node which have multiple field with image. i need image url in array format.