If there is an image in the 'body' field, then none of the regular text is outputted - only the image path is in the JSON string. If I remove the image from the field, then all the text is properly outputted.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rrrob’s picture

The offending code block is in views_json.module lines 174-189:

$img_match = array();
$src_match = array();
if (is_array($field_output)) {
  foreach ($field_output as $i => $f) {
    if (preg_match("/<img[^>]+>/i", $f, $img_match)) {
      if (preg_match('/(src)="([^"]*)"/i', $img_match[0], $src_match))
      $field_output[$i] = ($src_match[2]);
    }
  }
}
else {
  if (preg_match("/<img[^>]+>/i", $field_output, $img_match)) {
    if (preg_match('/(src)="([^"]*)"/i', $img_match[0], $src_match))
      $field_output = ($src_match[2]);
  }
}

What is the purpose of this?

rrrob’s picture

Is it safe to assume that the purpose of this code block is to strip everything but the url from image fields? I can see where this would be useful, but the Image URL Formatter module already handles this.

This code needs to be removed from all 4 modules of this project.

rrrob’s picture

Alexander Allen’s picture

Many thanks for the patch deckerdev. I do agree with you that those lines of code are more crusty than a New York-style, thin crust, burnt Domino's pizza. I also find that "regexing" all rendered fields for an image in order to intercept it and modify the output is ugly. Be aware however that I've created issue #1699368: #RVDA: Rewrite Views Datasource's Architecture, and that this fix will be incorporated into that. As of now #1699368 is a priority (it does change all plugins, FYI), and I will make sure to look into this issue after #1699368 is complete.

Alexander Allen’s picture

Issue tags: +API change
Alexander Allen’s picture

Status: Active » Closed (duplicate)

Marking as duplicate to reduce size of active queue.
Again, will be fixed for #1699368, but it has been added to issue #1623606: Views Datasource 2.x branch for QA testing.

Thank you.

whastings’s picture

I had to make a version of the patch in #3 for a Drupal 6 site, so here it is in case anyone else needs it. I made it against 6.x-1.x-dev