- Issue created by @candelas
- 🇫🇷France DrDam
Hi,
First thanks for asking for a such challenge.
And if it's fit with what you need to do, yes, of course it was a good addition to the collection (maybe in a "specific migration module")
Before all, did you have allready test the media_contextual_crop collection on a fresh D10 site ? and if it correspond to the use case with media (using media_contextual_crop reference) and image_widget_crop ?
I just need more details of implementation/configuration to answer you as well as possible. I forgot a large part of how manual_crop works in D7 (not having the technical interest in this subject at the time).
Based on Basic configuration ( See Here → )
In "very short" :
- I have patch "crop" entity to add an new "database field" name "context" (in crop_field_data table) in order to "store" the "context of the crop".
- This context are "calculated" by the methodMediaContextualCropService::getBaseContext
So in "very theoricaly", you just need :
0. Migrate value from "D7 field" to a D10-media_reference_with_context" field
1. "recalculate" the context of the image ( format : EntityType:BundleName:EntityId.FieldName.Delta , it's the same way than media_library_media_modify module context )
2. Extract data from manual_crop :
- image style,
- the local image (file object)
- crop "settings" ( point X, point Y, Height, Width)
3. Create a new crop with parameters :$values = [ 'type' => $crop_type, 'entity_id' => $file->id(), 'entity_type' => 'file', 'uri' => $field_uri, 'context' => $context, ]; $crop = $cropStorage->create($values); $axis_coordinate = Drupal::service('image_widget_crop.manager')->getAxisCoordinates( ['x' => $crop_values['x'], 'y' => $crop_values['y']], ['width' => $crop_values['width'], 'height' => $crop_values['height']] ); $crop->setPosition($axis_coordinate['x'], $axis_coordinate['y']); $crop->setSize($crop_values['width'], $crop_values['height']); $crop->save();
Et voilà (maybe not, but it's theorical)
- Assigned to DrDam
- 🇪🇸Spain candelas
Merci beaucoup!
I will be able to continue tomorrow.
I will report here my progress.
Bonjour - 🇫🇷France DrDam
I think I have miss something,
In stage 0 : "Migrate value from "D7 field" to a D10-media_reference_with_context" field"
The data structure in media_with_contextual field are a little tricky, the basic structure are identical to a reference field type with another "field in table" []_overwriten_property_map which save "contextual data".
an exemple with Image widget crop, the table node__[field_name] contain :
So I don't know how data are saved in the D7 field, but we need "image_widget_crop widget RAW value" in the field data.
In fact (sorry for that), all other stages listed previously are useless. We just need this "value" correctly set, and the image file attache to the correct media ([fieldname]_target_id )
- 🇫🇷France DrDam
Hi,
I continue with some intels for you.
I confirm what I'm saying in #6 you didn't need populate crop entities, you just need populate the "media_reference_with_context" field and save the node. #2 are totally use-less in this case, Crops will be populated by formaters, so it's in the node rendering will populate them.
- 🇫🇷France DrDam
@candelas :
did you have an idea what you would make in this migration process ?
- Image_style configuration update ?
- field type migration (as #3415387 💬 The focal point option isn't in the select on Media images field Fixed ) & config ?
- data migration ?
- 🇪🇸Spain candelas
Sorry, I am very very tired, make mistakes and make you loose time.
I go to rest and then keep working :)
I have to migrate the D7 field image to D10 field media with contextual modifications.
I am thinking in not migrating manualcrop module crops since your module with focal point can make the images derivatives for the breakpoints.
Thanks - Status changed to Closed: works as designed
10 months ago 5:11pm 18 January 2024