REST views: using DataFieldRow's "raw_output" option causes entity reference fields to output NULL

Created on 17 December 2015, over 8 years ago
Updated 23 January 2024, 8 months ago

Spun off of #2574077: REST Export display cannot show any raw output for fields using the Field field handler β†’ , dependent on commits from that issue

Problem/Motivation

If you have a view, add a REST Export display, use the Field field handler, and set "raw output" on a reference field (ie File, Image, Content, etc.), it always outputs "null" instead of an actual value.

Basically, this:

Causes this:

    {
        "title": "Test Page title",
        "field_test_image": null,
        "field_test_content_reference": null,
        "field_test_taxonomy_reference": null
    }

Proposed resolution

I think the issue stems from FieldItemBase::__get.

  public function __get($name) {
    // There is either a property object or a plain value - possibly for a
    // not-defined property. If we have a plain value, directly return it.
    if (isset($this->properties[$name])) {
      return $this->properties[$name]->getValue();
    }
    elseif (isset($this->values[$name])) {
      return $this->values[$name];
    }
  }

Files have target_id's, not names, so they get to this point and break.

Remaining tasks

Fix it
Tests

User interface changes
API changes
Data model changes

πŸ› Bug report
Status

Closed: outdated

Version

9.3

Component
RESTΒ  β†’

Last updated 6 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States charginghawk

Live updates comments and jobs are added and updated live.
  • VDC

    Related to the Views in Drupal Core initiative.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024