Created on 23 June 2021, about 4 years ago
Updated 23 March 2023, over 2 years ago

Problem/Motivation

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.

Steps to reproduce

  1. Add crops to media image
  2. Attach media created in step 1 to any node.
  3. Try to import node created in step 2 from any client site.
  4. Node and media will imported successfully on client but not the crops in media image.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

โœจ Feature request
Status

Active

Version

3.0

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia bunty badgujar Delhi

Live updates comments and jobs are added and updated live.
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.

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance Grimreaper France ๐Ÿ‡ซ๐Ÿ‡ท
  • Issue was unassigned.
  • ๐Ÿ‡ซ๐Ÿ‡ทFrance Grimreaper France ๐Ÿ‡ซ๐Ÿ‡ท

    Hi,

    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:

    โœจ JSON API integration Active

    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.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States pbabin

    We'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.

  • Hello @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.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States pbabin

    Thank you @grimreaper for linking this issue to โœจ JSON API integration Active !

    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. 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.

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance prudloff Lille

    I tried the patch from โœจ JSON API integration Active 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:

    [notice] Error during import. The field crop does not exist.

    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.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium blacksnipe

    Hi

    I've applied the MR for โœจ JSON API integration Active 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!

  • Status changed to Postponed: needs info 3 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom joachim

    This is RTBC but I don't see an MR or a patch here.

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance MaxPah

    Hello,

    I can confirm, it's works well with patch from #2890651 (crop module)

    So, no patch needed in entity_share module.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom joachim

    Thanks for reporting back!

    In that case, I'll close this.

  • Status changed to Closed: works as designed 28 days ago
  • ๐Ÿ‡ซ๐Ÿ‡ทFrance prudloff Lille

    At least part of my problem in #10 was related to this โœจ JSON API integration Active so in case anyone else has the problem : the "administer crop" permission is need to get crop entities from the JSON API.

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance Quentin Massez

    Hello 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 โœจ Support Crop API Active ?
    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?

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom joachim

    > 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.

Production build 0.71.5 2024