I have a view that is outputing a single integer field for each row using JSON. If a field has the value 0 it is not being displayed. I think the problem is here on line 158 of views_json.module:
158 if (empty($field->options['exclude']) && ($field_output != "") && !empty($field_output)) {
159 $object = new stdClass();
If $field_output = 0 then !empty($field_output) will return FALSE and the field will not be rendered.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | views_datasource-empty_behaviour-1499518-2.patch | 983 bytes | rooby |
| #1 | views_datasource-empty_behaviour-1499518.patch | 1.21 KB | kle |
Comments
Comment #1
kle commentedThank you - I was searching this lines...
Here is a Patch which respects the 'empty'-behaviour in a better way:
1. it's hidden only if it is empty AND "Hide if empty" is TRUE
2. if it is displayed but is empty AND a "No results text" is given -> this text is used.
Maybe not perfect but better than before.
Nice work anymore - greetings from Cologne.
Comment #2
rooby commentedThanks for the patch.
It didn't apply for me for some reason but here is a re-roll with a couple of minor changes.
There were a couple of whitespace and comment changes and where it occurs I replaced:
with:
Because empty() also covers "".
Comment #3
alexander allen commentedGreat job. I also had the same issue. I tested all the use cases mentioned in comment #1 and the solution works as expected. The re-rolled patch didn't apply cleanly for me, I think the patch needs to be created relative to the project itself and not a particular file.
Committed into 7.x-1.x.
Comment #4
alexander allen commentedComment #5
alexander allen commentedComment #6
alexander allen commentedI'm sorry, the correct status is fixed.
Comment #8
muhleder commentedThis also applies to the 6.x branch. The same patch works.
Comment #9
yannickooFixed with 3fc7248.
Comment #10
yannickoo