Hello,

Summary

I have an image field on a 'document' file type (I've got file_entity enabled).
Saving a crop on the field (and then saving the doc) only works once. After the first time the crop is no longer saved.

Modules enabled:

- Latest manualcrop dev
- file_entity 7.x-2.0-beta2

+ dependencies

Steps to reproduce

  • Clean Drupal 7
  • Enable dev manualcrop and file_entity + dependencies
  • Add manual crop to one of your image styles
  • Add an image field to the 'document' file type admin/structure/file-types/manage/document/fields, enable manualcrop on that field
  • Upload a document at admin/content/file
  • Edit the document at the same location
  • Upload an image using the image field on the document
  • Manualcrop it
  • Save the document
  • Click to edit the document
  • Go to change the crop you did earlier then save the document
  • Click to edit the document again!
  • Check the crop and note that the previous crop did not save

Thanks for any help on this... and also for the great module! I've been using it with great success for several years now.

All the best,

Andrew

Comments

Andrew Edwards created an issue. See original summary.

Chris Charlton’s picture

Still an issue?

trackleft2’s picture

It appears as though a workaround is to install file_entity_revisions (https://www.drupal.org/project/file_entity_revisions) since the culprit causing this is this line in the manualcrop.module.

  if (isset($form['#form_id']) && $form['#form_id'] == 'file_entity_edit') {       
    // Skip the file_entity_edit form because it may use revisions and             
    // we want to save our crop data when the revision id is known.                
    return;                                                                        
  }              

As part of
function manualcrop_field_attach_submit($entity_type, $entity, $form, &$form_state)

MAkes sense that it breaks the functionality since the file_entity_edit form is told to skip saving using
manualcrop_croptool_submit($form, $form_state);

The whole submit function is here with the key line being manualcrop_save_crop_data(file_load($fid), $data['styles']);:

/**                                                                              
 * Form submit handler; Saves each crop selection.                               
 */                                                                              
function manualcrop_croptool_submit($form, &$form_state) {                                                                                                                                                                                                                    
  static $submitted = FALSE;                                                     
                                                                                 
  if (!$submitted && !empty($form_state['manualcrop_data']['selections'])) {     
    // Loop trough the selections to save them.                                  
    foreach ($form_state['manualcrop_data']['selections'] as $fid => $data) {    
      // In general this file entity should be loaded from a cache, so this      
      // should not cost any performance.                                        
      manualcrop_save_crop_data(file_load($fid), $data['styles']);               
                                                                                 
      // Clear the cached versions of this image.                                
      image_path_flush($data['path']);                                           
    }                                                                            
                                                                                 
    if (variable_get('manualcrop_cache_control', TRUE)) {                        
      // Clear the cached image paths.                                           
      cache_clear_all('manualcrop:', 'cache', TRUE);                             
    }                                                                            
                                                                                 
    // Show a success message when not using the FAPI.                           
    if (!empty($form['manualcrop'])) {                                           
      drupal_set_message(t('The crop selections have been saved.'));             
    }                                                                            
                                                                                 
    // Prevent additional submits.                                               
    unset($form_state['manualcrop_data']['selections']);                         
    $submitted = TRUE;                                                           
  }                                                                              
}                                    

BTW I did install file_entity_revisions on my site and was able to save crops for an image field on video file_entities.

Also if I comment out the condition that skips the submit function this also works.

trackleft2’s picture

I am adding this for my install profile, may not work with file_entity_revisons

joegraduate’s picture

@trackleft2 I wonder if, rather than removing the code that skips saving the crop on the file_entity_edit form, it would be better to make that code conditional depending on if the file_entity_revisions module exists?

trackleft2’s picture

trackleft2’s picture

Status: Active » Needs review
trackleft2’s picture

  • Matthijs committed 39240e9 on 7.x-1.x authored by trackleft2
    Issue #2558527 by trackleft2, Matthijs: Fixed crop not being saved for...
matthijs’s picture

Status: Needs review » Fixed

I've merged the 2 if's into one and committed the patch, thanks!

Status: Fixed » Closed (fixed)

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