Problem/Motivation

manualcrop_file_presave() does:

    $file->manualcrop_data = manualcrop_load_crop_selection($file->uri);

so that $file->manualcrop_data is an array keyed with style names with objects as values. (so an array of objects)

However:

manualcrop_entity_update does:

  manualcrop_save_crop_data($file, $file->manualcrop_data);

but manualcrop_save_crop_data expects an array of arrays.

Proposed resolution

Deal with arrays and objects by converting objects transparently into arrays.

Remaining tasks

- Do it

Comments

Fabianx created an issue. See original summary.

fabianx’s picture

Status: Active » Needs review
StatusFileSize
new507 bytes
nitebreed’s picture

Status: Needs review » Needs work

With this patch I get the following error when adding a image trough Media (with 2 crops) and after setting the crops:

PDOException: SQLSTATE[HY000]: General error: 1364 Field 'x' doesn't have a default value: INSERT INTO {manualcrop} (fid, vid, style_name) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => 171 [:db_insert_placeholder_1] => 0 [:db_insert_placeholder_2] => project_image ) in drupal_write_record()

peximo’s picture

StatusFileSize
new537 bytes

I can replicate the issue: if a user don't crop the uploaded image and the crop isn't required, the cast transforms the selection from false to an array and so the selection is saved generating the SQL error. I think we have to cast to array only the object selections. Attached patch should fix the problem.