1

Is anybody using the json_expand plugin for API functionality? For the entry type Rich Text Field its just returning an empty object.

This is my json_expand endpoint:

{% header "Content-Type: application/json" %}
{% set utensils = craft.entries.section('utensils').find('') %}
{{ utensils | json_expand | raw  }}

It's returning everything except that Rich Text field which just returns this:

"utensil_textbox": {}
2
  • Total shot in the dark, but scroll to the bottom of this thread I was having a similar problem with using the ElementAPI + rich text field.
    – Damon
    Feb 17 '16 at 17:35
  • Never used JSON Expand plugin, but try this: {{ utensils.getRawContent() | json_expand | raw }}
    – Brad Bell
    Feb 17 '16 at 17:37
3

I just came across this problem and solved it by editing the JsonExpandService.php file (located in craft/plugins/jsonexpand/services/) in two places.

Change line 101 from this:

$relatedArray[$subHandle] = $subValue;

To this:

if($subField['type'] == "RichText") {
    // Rich Text field values need to be converted to a string
    $relatedArray[$subHandle] = (string)$subValue;
} else {
    $relatedArray[$subHandle] = $subValue;
}

And change line 115 from this:

$entryData[$handle] = $value;

To this:

if($field['type'] == "RichText") {
    $entryData[$handle] = (string)$value;
} else {
    $entryData[$handle] = $value;
}

This fixed Rich Text fields coming through as empty objects for me.

This plugin hasn't been updated in 3 years, so Craft probably changed something about how Rich Text fields are outputted and the plugin never adjusted. Just a guess.

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.