When creating a view with a REST export (using JSON) that displays fields, certain fields show empty values in the JSON.

E.g. I added a number field and a text field to a content type, whose values are empty in the JSON output. The node title and content type fields' values do show up however. I chatted about this with @dawehner on IRC, he was seeing the same behaviour.

When I display full entities in the view, all fields have their correct values in the JSON output.

Comments

brunodbo’s picture

Title: Some fields have empty values in a view JSON export » Some fields have empty values in a view REST export (using JSON)
Issue summary: View changes
dawehner’s picture

Title: Some fields have empty values in a view REST export (using JSON) » Fieldapi fields have empty values in a view REST export (using JSON)
Status: Active » Needs review
StatusFileSize
new4.81 KB
new5.42 KB

There we go.

Status: Needs review » Needs work

The last submitted patch, 2: rest-2137305-FAIL.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new5.42 KB

Let's just upload the working one.

Status: Needs review » Needs work

The last submitted patch, 4: rest-2137305-PASS.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review

4: rest-2137305-PASS.patch queued for re-testing.

brunodbo’s picture

Confirming that the patch in #4 fixes the issue: fieldapi field values are now displayed correctly in a view REST export.

damiankloip’s picture

  1. +++ b/core/modules/rest/lib/Drupal/rest/Tests/Views/StyleSerializerTest.php
    @@ -289,4 +289,13 @@ public function testPreview() {
    +  public function testFieldapiField() {
    

    Let's have a docblock :)

  2. +++ b/core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_node_display_field.yml
    @@ -0,0 +1,120 @@
    +module: rest
    

    module should be rest_test_views?

dawehner’s picture

StatusFileSize
new1.3 KB
new5.5 KB

module should be rest_test_views?

Wow, you really read that yml file!

damiankloip’s picture

Status: Needs review » Reviewed & tested by the community

Yes, this is good.

webchick’s picture

9: rest-2137305.patch queued for re-testing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 9: rest-2137305.patch, failed testing.

swentel’s picture

Status: Needs work » Needs review

9: rest-2137305.patch queued for re-testing.

swentel’s picture

Status: Needs review » Reviewed & tested by the community

Pretty sure, the last failure was a problem with the bot and/or network - we'll see who's right .. :)

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 7a0b674 and pushed to 8.x. Thanks!

       if (($field->field_alias != 'unknown') && !empty($this->rawOutputOptions[$id])) {
         $value = $field->sanitizeValue($field->getValue($row), 'xss_admin');
       }
-      // Otherwise, pass this through the field render() method.
+      // Otherwise, pass this through the field advancedRender() method.
       else {
         $value = $field->advancedRender($row);
       }

fixed the code comment during commit.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.