Active
Project:
Entity Share
Version:
8.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
23 Jun 2021 at 12:35 UTC
Updated:
30 Oct 2025 at 20:46 UTC
Jump to comment: Most recent
I am using entity share module with Media entity and crop API.
Adding crops to media image attached to node in source are not created on client site.
Comments
Comment #2
grimreaperThe list of supported field types is on https://www.drupal.org/docs/8/modules/entity-share/supported-field-types.
Currently Entity Share does not explicitly support Crop API, so it is a feature request and not a bug.
Comment #3
maxpahHello Grimreaper,
I have a website who also need this feature. As you must be more comfortable with JSONAPI and entity_share, would it be possible to have the steps to make an entity compatible like Crop and FocalPoint.
I think about these steps :
Then I can propose a patch, thanks for your help.
Jsonapi output for crop types
Jsonapi output for crop focal-point
Comment #4
maxpahHello @Grimreaper,
Is it possible to have input for this feature ?
Comment #5
grimreaperassigning
Comment #6
grimreaperHi,
I finally got time to give a look at this issue.
I confirm this is not a problem related to Entity Share but the Crop API module:
#2890651: JSON API integration
So solution will both work for Focal Point and Manual crop or any kind of crop.
As crop type is a config entity, it should be the same between your client and server website.
As you mentioned the problem is that there is no proper relationship between a crop content entity and the image file entity it is applied on.
And there is also that in the attributes of this content entity, there is
"entity_id":1, which is an ID and not an UUID.I think what could be done as a workaround to automatically import the crop:
1. in the image field output add information of the (or the multiples) crop content entity JSON:API URLs. How?
- With a normalizer like you proposed?
- or maybe like in comment #2890651-14: JSON API integration
I think the place for this is in the Crop API module.
2. add an event subscriber on RelationshipFieldValueEvent or an import plugin processor that will read this or these URLs to import automatically the crop content entity.
But the crop content entity would need to be prepared:
3. create a field enhancer to transform the "entity_id" attributes into a UUID and the opposite in doTransform().
This field enhancer could reside either in Entity Share or in the Crop API module. Maybe better in Crop API.
4. should the uri attributes on crop content entity be ignored or will require special treatment too? will the physical file be regenerated automatically?
I will also ping in the other issue to ask for feedbacks.
Comment #7
pbabin commentedWe're looking at needing something like this as well. Has anyone been able to successfully do this and can share their code? We're just using crop api with image widget crop. I see in the database all the points that @maxpah and @grimreaper are making so I think we should be able to pass the crop information along; however, I am at a loss of where to start. It doesn't look like there is any traction on the crop api side. So is it advisable to add these modifications into our own module and try the import?
Any guidance to point me in the right direction is greatly appreciated. Entity share is such an amazing tool and our organization is extremely grateful for all that it does!
Thank you in advance.
Comment #8
rishabjasrotia commentedHello @pbabin,
In one of our project we faced similar problem.
The solution was implemented using custom module to bind another extra field which stores the crop positions data.
Once the data is synced we wrote code to use those field value and apply crop to image.
Comment #9
pbabin commentedThank you @grimreaper for linking this issue to #2890651: Crop API - JSON API integration!
I've applied the MR !9 patch from #2890651 and the crops are being brought over with Entity Share! Please note that my setup included a locked policy. With the policy turned on, the crops did not come over. Meaning that entity share registered that there was a crop to bring over, it brought over, however, the values for the crop were not applied. I've converted the policy to create only and the crops come over and are applied correctly.
So much gratitude for this package! Thank you.
Comment #10
prudloff commentedI tried the patch from #2890651: JSON API integration and it correctly adds a crop computed field on file API responses.
But it does not seem to be enough. I get this notice and the crop is not imported:
I suppose entity_share does not know what to do with a computed field?
I guess an enhancer could handle this.
Also the "changed" property of files is not updated when the crop changes, so entity_share_cron will not try to reimport the file when its crop has changed.
Comment #11
blacksnipeHi
I've applied the MR for #2890651: JSON API integration via composer.
After some debugging, the data for focal point and cropping came through.
The patch needs to be applied to both server and client(s) for it to work.
Tested and approved for our case.
Thanks for the contribution everyone!
Comment #12
joachim commentedThis is RTBC but I don't see an MR or a patch here.
Comment #13
maxpahHello,
I can confirm, it's works well with patch from #2890651 (crop module)
So, no patch needed in entity_share module.
Comment #14
joachim commentedThanks for reporting back!
In that case, I'll close this.
Comment #15
prudloff commentedAt least part of my problem in #10 was related to this so in case anyone else has the problem : the "administer crop" permission is need to get crop entities from the JSON API.
Comment #16
quentin massez commentedHello everyone,
I encountered a problem while trying to import my crop "focal_point" using Entity Share and the MR in #2890651.
The crops are imported, but they have the entity_id of the source file ID.
Example:
I have a file (let's say ID = 10) on my source website with a crop at x=100, y=200.
After import, the file is correctly imported on my destination website (with ID = 20), and I get a row in the crop_field_data table that contains: entity_id=10, x=100, y=200.
I believe this issue relates to point 3) in https://www.drupal.org/project/entity_share/issues/3220320#comment-14981040?
I'm not sure how we should handle this.
One workaround could be to update the entity_id of the crop in hook_file_update : this works, but it doesn’t seem like the best solution.
Maybe there's something specific in my setup, since it looks like you're not encountering this issue?
Comment #17
joachim commented> the "administer crop" permission is need to get crop entities from the JSON API.
That's pretty bad for security! User accounts which are used by APIs should have permissions which are as limited as possible.
If there's a patch for adding a 'view' permission for crop entities, we can recommend it in the README here, as we already do for some other entity types.
Comment #18
pbabin commentedI've submitted a related merge request to the Crop API module that should help address part of the problem discussed here.
The patch introduces a “view only” permission, an access controller, and updates to expose certain Crop entity fields to JSON:API.
It also updates the parent entity timestamp whenever a crop changes — this allows tools like Entity Share to detect and re-import those updates. In testing, this timestamp change was the only reliable way to ensure re-syncing of modified crops.
This behavior and and an additional required hook are further detailed in a related inquiry here: Crop API - Crop Updates and Entity Share.
I’m continuing to refine the approach and welcome any feedback from maintainers or others working on Entity Share integration.