I understand the reasons why this module avoids the synchronization of user and config entities. However, there should be an entry point for custom code to fill this information when needed. For example, depending on the adopted solution, a user can be linked to the entity by just checking the username as it might have already been pulled by some SSO mechanism.

Thus, I suggest that a hook is provided allowing third-party modules to change the imported entity before it is saved. It differs from hook_entity_presave() as the decoded JSON response would be passed to the hook implementation along with the entity object. I also recommend passing along an HTTP client configured for the remote to allow modules to get more information about the referenced entities, like the username. Another option would be passing the JsonapiHelper object, but its getHttpClient() method is protected.

Inspecting the code, I think the changes should be made to the Drupal\entity_share_client\Service\JsonapiHelper::importEntityListData() method.

I could try to provide a patch for this.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dbiscalchin created an issue. See original summary.

dbiscalchin’s picture

Issue summary: View changes
Grimreaper’s picture

Hello,

Thanks for your interest in the module and your suggestion.

Instead of a hook, it would be better to add an event.

msti’s picture

Title: Hook to alter imported entities » Event to alter imported entities
Version: 8.x-2.x-dev » 8.x-1.x-dev
FileSize
11.73 KB

Hi,
This patch adds 3 Events. It allows the developers to alter the entity at 3 stages:

  • Alters the entity data prior to entity initialization. Useful if you want to prevent fields from syncing
  • For new entities, alter the entity prior to inserting
  • For existing entities, alter the entity before updating
msti’s picture

Status: Active » Needs review
msti’s picture

This is the correct patch

msti’s picture

Grimreaper’s picture

Assigned: Unassigned » Grimreaper
FileSize
9.21 KB
9.77 KB

Hello,

For #3064331: Compatibility with block field, I had to add event.

So I will merge the patch. Attached is a new patch taken from 7.

Remove changes in Remote.php and change an event name and fixes CS.

Waiting for automated tests results before merging.

Also warning, MAYBE during rework in #3060694: Rework service and tests some changes will occur to events.

Grimreaper’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev

  • msti authored 1e0a9eb on 8.x-2.x
    Issue #3003823 by msti, dbiscalchin, Grimreaper: Event to alter imported...
Grimreaper’s picture

Assigned: Grimreaper » Unassigned
Status: Needs review » Fixed

Merged!

Thanks for your contribution!

Status: Fixed » Closed (fixed)

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