Summary

Domain Access module prevents REST file upload due to NULL exception in domain_access.module (domain_access_entity_field_access).

Proposed solution

Check whether $items is NULL before accssing it, in accordance to function signature (see attached patch).

Comments

pvbergen created an issue. See original summary.

pvbergen’s picture

Issue summary: View changes
StatusFileSize
new1008 bytes
agentrickard’s picture

Status: Active » Postponed (maintainer needs more info)

I need reliable steps to reproduce and test this bug report.

pvbergen’s picture

Sorry for keeping this issue abandoned so long.
We encounter this issue when we want to use the /file/upload/{entity_type_id}/{bundle}/{field_name} endpoint to upload images (see https://www.drupal.org/node/2941420).

Problem

The response of an upload to the file upload REST endpoint is empty due to an error in domain_access.module:
Error: Call to a member function getEntity() on null in modules/contrib/domain/domain_access/domain_access.module on line 433

Steps to reproduce

  • Install Drupal (>8.6), enable media module (core)
  • Install and enable restui
  • Install and enable domain, domain_access
  • Create a media type "image" using the "image source" plugin and name the field "field_media_image"
  • Enable the file upload enpoint in /admin/config/services/rest
  • Execute a POST request to /file/upload/media/image/field_media_image?_format=json with an image payload according to https://www.drupal.org/node/2941420
  • The response is empty, although it should contain the JSON representation of the file entity.

Side note

According to the definition of the hook_entity_field_access, the $items parameter is optional, so we should check $items before accessing it.

agentrickard’s picture

Status: Postponed (maintainer needs more info) » Needs work

Great report, thank you.

agentrickard’s picture

StatusFileSize
new907 bytes

Slight patch for clarity of documentation. Tests all pass.

agentrickard’s picture

Status: Needs work » Fixed

Committed and credited!

Status: Fixed » Closed (fixed)

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