Needs review
Project:
Views Datasource
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Issue tags:
Reporter:
Created:
16 Sep 2010 at 16:21 UTC
Updated:
18 Jul 2017 at 21:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
jonathanmd commentedI just ran into a similar problem when trying to combine multiple column fields. Whenever the field contains an img tag the entire contents of that field get replaced with only the source of that image.
I'm making an RSS feed and combining a text summary and image into an element called description and wrapping it with CDATA so that it still validates. However, I keep running into the problem above where the entire contents of the field are replaced with the img src.
Line 133 of views_datasource.module (similar replacements occur in the other .module files)
I was going to create a patch for this that only replaces the img with its source and not the entire field, but I couldn't think of a usecase where you'd want to replace images with the src. Developers already have ability to select whether or not to use the entire image or just the image path from within the view.
Is there a reason to always have images stripped out or can that part of the code just be removed?
Comment #2
allisterbeharry commentedjonathanmd is right - it was a quick hack to solve an issue in the Imagecache module that should only be inserted when selected as an option. Will be fixed in the next release.
Comment #3
pschopf commentedThis issue presents several interesting problems. We ran into this when trying to feed nodes from one site to another. Any field with an
tag in it would reduce to the contents of the src attribute. But the choice of leaving the whole
item in the field gives us additional problems: If the src attribute is a relative address (src="/sites/default/files/xyz.png") any import of this field to another site will probably produce a missing image. If the src attribute is an absolute address, then the exported field would be fine. The option of removing all
elements would be OK for some, but probably not for others.
Would it be OK to convert all relative addresses to absolute?
Comment #4
michellezeedru commentedSubscribing. Has a fix for this problem been committed to the dev version yet? Are there any recommendations for what I can do until there is a fix?
Thanks!
Comment #5
steel-track commentedHas any headway been made on this? It is a pretty serious issue on a project I am working on, but I don't want to start making patches if it's already being addressed. I am currently using the dev version from Feb. 25th.
Comment #6
chromix commentedSeconding #5. I've currently just commented out
$img_match = array();down to the end of the if block.Comment #7
span commentedI'm not sure if this is related but it is truly a weird problem that I haven't really dug into yet.
I've got a view that creates some JSON output. It seems that as soon as the JSON runs into an image in my node->body field it takes the image into the JSON source and then it stops. This leads to any body field that begins with an image and then has some body text will only show up in the JSON as the image path. When there is some text before and after an image, the image path is still the only thing that shows up in the JSON output.
Setting the node body to "strip html tags" makes all the data come into the JSON object but I do need the tags so I can't use this workaround. Also tried using the dev version with no luck.
Looked into this a bit and ended up with this that solved my immediate problem:
views_json.module line 133
Removing this piece of commening does the trick on getting all the contents back for me. Surely it is not a good solution for everyone but could be useful for anyone with a specific need.
Comment #8
jaarong commentedI'm running into this same issue. I found that switching to raw output instead of normal fixes the issue, but I'm not sure exactly why I have to do that and what that means for other outputted data.
Comment #9
fangel commentedI too ran into this issue, and while I understand the reason for this functionality, I find it too aggressive in it's replacement.
Say you have a media-field, then it's very likely that you would JSON field represented as the images source, not a
-tag. But in all the use-cases described here (basically a html-field that contains
s)
My proposed fix is to change the
-regex to only match if the entire field-output is the
-tag. This maintains the media-field src-substitution functionality while still allowing html-fields to contain images.
Comment #10
guybedford commentedGreat module!
I also had to comment out these lines, as I'm outputting full node data with views node field (drupal.org/project/viewsnodefield).
Comment #11
floydm commented@allisterbeharry - I'd be happy to try to create a patch for this if I understood when that block of code is necessary. For the time being I'm doing what everyone else is doing and just commenting it out.
-Floyd
Comment #12
hbfkf commentedSubscribing.
Comment #13
bigjim commentedWe're experiencing this in the 7.x dev branch also
Comment #14
biteuljiouce commentedsame for me, I'm trying to get the content (html) of a text field of a node. This field may contain both text and images. And I couldn't get the whole.
here are some examples :
source content :
field format "raw" (I'm getting only text) :
" encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte "field format "default" (img url only) :
"http://www.pierrelapolice.local/cms/sites/default/files/resize/field/ima..."
field format "cut = 600" :
<p> </p>\n<p>encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte encore du texte </p>\n<p> </p>field format "cut = 650"
"http://www.pierrelapolice.local/cms/sites/default/files/resize/field/image/%20bssc0255-devon_aoki-lachapelle-300x415.jpg"(I installed Drupal in french, so I'm gessing the name of the field format).
Comment #15
biteuljiouce commentedmaybe we could check what type of field it is ?
with Drupal 7 (maybe 6 ?), i can test the value of field_info['module'].
Comment #16
jyraya commentedConversion of relative addresses to absolute, mentioned by pschopf, seems to be a good solution. Nevertheless, if we consider the question of performances, that could be tricky. the conversion treatment increases the view rendition time and it is especially true for sites with a huge number of concurrent users and a lot of content to render.
For me, this treatment, if requested, should rather be done at node edit/creation time than here.
Comment #17
lisa.rae commentedHey Guys,
We ran into the same problem on a project where we were setting up a web service for an iPad app, and pulling down information to store locally on the iPad through the json feed. The problem we ran into is that we had some fields that were storing uploaded images in an Image field, which we needed to download from the image URLs, and we had some content that had imbedded
<img>tags in the body field using a wysiwyg editor, which was getting munged by the code block in question.When we commented out the block of code, we were no longer getting the information on the images stored in an Image field, but our body fields with imbedded
<img>tags was coming across fine.Our solution is to replace the block of code referenced in comment #9 above with the following:
We're now getting the URLs for images that are uploaded into an image field, and we're preserving the HTML content, including imbedded
<img>tags, in the body fields. We haven't tested this for all media types, but I suspect that it should work ok. If someone else could test as well and confirm that this is a workable solution, we'll prepare and submit a patch.Lisa
Comment #18
jrglasgow commentedI have resolved this on my system by editing it to call another function that searches for all img tag sources, checks to make sure the url is absolute, and if not it makes it absolute.
Here is my patch against 7.x-1.x
Comment #19
Anonymous (not verified) commentedtried patch in number #18 first but this only works if you don't have single image fields. otherwise it breaks stuff.
if you have single image fields but also text fields containing images use #17 it works nice for me.
thanks allot!
Comment #20
rajab natshahSeems that last fix code is not a fix for each Field states.
I have this patch for it.
Comment #21
rajab natshahDo no use this patch it's was for the master branch .. Obs ... the patch file in comment #22 is the right one. it's for the 7.x-1.x branch.
Comment #22
rajab natshahThis is the right patch file for views_datasource-7.x-1.x to have many images in html field and image path for image fields
Comment #23
rajab natshahComment #24
rajab natshahSeems that different View's Options will effect the output ..
This code will work. for HTML .. in Default View ..
We should fix this not to have img tags or any other tags in none HTML Fields.
Comment #25
emattias commentedHere's the same patch as #24 but it avoids notices when $field->options['type'] doesn't exist.
Comment #26
ishmael-sanchez commentedThe patch in #25 works great. Tested it with multiple images.
Comment #27
zserno commentedIndeed, patch in #25 worked for me as well.
Comment #28
ConradFlashback commentedThis problem runs also with xml.
Comment #29
ken hawkins commentedSeconding that this fix works. Would be great to see committed.
Comment #30
jaymallison commentedRelated: https://drupal.org/node/1319714#comment-8681645
I made a patch to support multiple images in a field and add sub ordinals including the src and alt attributes. The code from that issue is joined at the hip with the code from this issue so I merged the patch from #25 with my original patch.
I'll post the patch here too so if anyone is interested in testing this - please give feedback.
Comment #31
jaymallison commentedNew patch that fixes the src/alt for single images.
Comment #32
batpurev commentedcomment #25 worked for me like a charm for D7.27 thanks a lot guys!
Comment #33
ndf commentedJust created JSON field formatter module.
It provides a field formatter for text fields that outputs encoded json. This works for body fields and could be useful for a bunch of above issues.
Comment #34
technicalknockout commentedWas experiencing this issue. So far #31 worked for me without issues.
Comment #35
b33tl3 commentedSame for me.
I need to output text field with html markup and many images (coming from media, inserted into wysiwyg with insert module).
views_datasource json outputs only a single img path and get rid of all other html and text.
#31 worked for me. MANY THANKS
PS : would be nice to commit this patch :)
Comment #36
jaymollica commentedHey everyone, not sure how useful this is, but I altered the views_json.module file to work with the image_field_caption module so that you can now associate image captions to the images in the json feed. I've attached the modified views_json.module, the caption stuff starts around line 188 and uses the same regex method to grab the captions, which I agree is not ideal. But it works in a pinch.
Comment #37
mrded commentedJust trying to apply #31 patch
Comment #38
mrded commented#25 & #31 patches need to follow Drupal code standards
Comment #39
issa.haddadinThe same problem is happening on views_xml.
I used the last patch from @mrded and implemented on views_xml and worked fine with me.
Comment #40
briand44 commentedThis is the same patch as #39 just applies against the latest dev.
Comment #41
alarcombe commentedThere's a fundamental problem with using the field type as an indicator for whether to rewrite an image field in that it doesn't work if you use an image field as a source for a rewritten field. The rewritten field will not be of type 'image' and so will be rendered differently than the source field.
Comment #42
alarcombe commentedAddressing the issue of rewritten fields I mentioned in #41, the attached patch provides a configuration option for the views_datasource display which determines whether views_datasource reformats the output of all fields that *start* "<img " or just those which are image fields. It's not perfect, but is more configurable than the previous resolutions to this issue.
Comment #43
kenorb commentedComment #44
akeemw commentedAdjusted the patch in #39 to work against the current release - 7.x-1.0-alpha2
Comment #45
berdyshev commentedpatch in #42 works for me, thanks