This module encounters a fatal error when croppable image fields are included in a profile2 entity: http://drupal.org/project/profile2

The problem has to do with the way $instance is selected around line 499 of imagefield_crop.module.

$instance = $form_state['field'][$element['#field_name']][$element['#language']]['instance'];

$profile2 puts that data in a different location in the $form_state array

$profile2_instance = $form_state['field']['#parents']['profile_business']['#fields'][$element['#field_name']][$element['#language']]['instance'];

Also, there's another error when profile2 forms are displayed programmatically via drupal_get_form()/render, there's an error when photos are uploaded. Basically, the user.pages.inc file is not automatically included. So around that same line where the instance is selected doing the following fixed it:

include_once drupal_get_path('module', 'user') . '/user.pages.inc';
$instance = $form_state['field'][$element['#field_name']][$element['#language']]['instance'];

There has no be some more intelligent way to make sure the required includes are loaded when imagefield crop does its ajax call.

I don't know technically who would be best to fix this, so I'm going to post about it in both issue queues.

Thanks!
-Brent

CommentFileSizeAuthor
#3 0001-Fixing-field-instance-issue.patch936 bytespwaterz

Comments

bdu’s picture

The profile2 issue for this is #1178370: Notice: Undefined index: field_photo in imagefield_crop_widget_process(). According to the profile2 maintainer this is probably due to imagefield_crop not being able to cope with embedded field forms.

thetoast’s picture

Same issue......I just wanted to add that I tested the image cropper on the user entity and taxonomy entity and it worked fine on both, and I also tested it with a custom entity (creating an entity using the eck module) and it also worked fine with that. So I'm just wondering, is it this modules issue why that error appears with profile2? As for adding the include file for user pages, I suppose if you're doing stuff like drupal_get_form then it shouldn't be a problem to add it yourself :-) ...... it's not uncommon to have to do stuff like that when you're writing custom code for drupal, for example, I've had to add it when calling drupal_get_form on the user password reminder form.

pwaterz’s picture

StatusFileSize
new936 bytes

Here is a patch that fixes this :) Enjoy!

pwaterz’s picture

Status: Active » Needs review
ridgek’s picture

Thanks, pwaterz!!!

calefilm’s picture

Thanks for patch Pwaterz :)

fraweg’s picture

#3 works perfect!

Thanks so much Pwaterz!

mattsmith3’s picture

#3 works great here too.

DeFr’s picture

Do note that a fix for this issue was commited to the 7.x-2.x branch (after the 7.x-2.0 release though) , in http://drupalcode.org/project/imagefield_crop.git/commit/a0e80f2ef8f611a... . The patch applies to the 7.x-1.0 release (with a kinda huge offset), and seems to fix the problem for me.

scotwith1t’s picture

Version: 7.x-2.x-dev » 7.x-1.0
Status: Needs review » Reviewed & tested by the community

Fixed the problem for me with 1.0. Can we get this committed? This makes this work on any image field on other types of entities, like Profile2.

citricguy’s picture

Possible duplicate: http://drupal.org/node/1369836

pav’s picture

#3 works great. thanks

joetsuihk’s picture

Status: Reviewed & tested by the community » Closed (fixed)
GaneshKumar’s picture

Thanks pwaterz for your patch.