Uncouple ImageField from FileField Custom Hooks

quicksketch - March 10, 2009 - 18:33
Project:ImageField
Version:6.x-3.x-dev
Component:Code
Category:task
Priority:normal
Assigned:quicksketch
Status:closed
Description

This is an extensive patch that fundamentally changes the way ImageField works.

The current ImageField in Drupal 6 attempts to piggy-back off of FileField while providing its own CCK field type. This approach requires ImageField to implement hook_field() and several FileField custom hooks, many of which are buggy or not being used at all.

I've been fixing several issues in the FileField queue, such as broken revision handling (#370531: Properly Handle Revisions for document control) and duplicate uploads (#370015: Upload issue with clicking 'Add another item' multiple times (Repost w/ screencast)). However, these problems still exist in ImageField since it uses it's own hooks for managing its fields.

In short, we've got a lot of duplicated code between ImageField and FileField, and the code that is shared between the two is shared by mechanisms that CCK was not made to handle (i.e. it's all a bit of a hack to work around limitations in CCK).

So this patch removes the "Image" field type, and makes ImageField a pure widget for FileField. This means less code in ImageField, more reuse, and less bugs. The only side-effect of this is that all the formatters specific to ImageFields are also now available to FileFields. However, ImageCache already provides all its formatters to FileField anyway, so this isn't that big a shift.

This patch refactors ImageField to make it a pure widget. It also fixes the upgrade path between the Drupal 5 1.x version of ImageField and the current 3.x. This patch needs to be applied to both FileField and ImageField at the same time.

AttachmentSize
filefield_imagefield_untangle.patch37.04 KB

#1

quicksketch - March 10, 2009 - 18:42

Revised patch with a few less code style fixes unrelated to the issue.

AttachmentSize
filefield_imagefield_untangle.patch 35.11 KB

#2

quicksketch - March 10, 2009 - 22:43

Updated patch that also regenerates thumbnails with a better path. This was suggested in http://drupal.org/node/385726#comment-1307422.

AttachmentSize
filefield_imagefield_untangle.patch 36.24 KB

#3

quicksketch - March 10, 2009 - 23:00

The upgrade path fix included in this patch also fixes #374764: Drupal 5 Update Breaks Titles and Alt text.

#5

quicksketch - March 10, 2009 - 23:40

#6

quicksketch - March 10, 2009 - 23:41

#7

quicksketch - March 11, 2009 - 01:43
Status:needs review» fixed

Considering the number of dependent issues on this one and my desire to get out a working upgrade path as soon as possible, I've committed this patch. At the very least it's going to fix more problems than it will cause.

#8

Rob Loach - March 11, 2009 - 22:59

Wow! Nicely done, Nate! Didn't even see this issue... ImageField code is good now!

#9

drewish - March 11, 2009 - 23:03

Saw one warning during the update:

notice: Undefined index: image_path in /Library/WebServer/drupal-6/modules/imagefield/imagefield.install on line 122.

#10

Boletus - March 11, 2009 - 23:12

This sounds great. Been waiting for the imagefield 6 forever. Good work! Will try to test this tomorrow. Can I use the dev version of ImageField and FileField and not patch anything, or what do you suggest?

#11

quicksketch - March 12, 2009 - 03:40

Thanks drewish, I put an isset() check in there. This would have caused upgrading from ImageField d6 to this new version to lose any custom file paths specified.

#12

himtuna - March 14, 2009 - 14:30

Hi, I don't know how to apply a patch.
Please can someone give me a working file of imagefield.module

That would be really thankful.

EDIT:Please this is an emergency, I am building my site and everything seems to be broken, I someone could send me a working module of filefield and imagefield. Please please please.

#13

quicksketch - March 14, 2009 - 14:49

himtuna: get the development versions which have all the patches applied. Visit the project page for ImageField and FileField, click "View all releases", then download the 3.x-dev versions.

#14

himtuna - March 14, 2009 - 16:04

Oh! Man thanks a lot
You know when you work hard all day long on our weekends, your head just don't work

Thanks a lot for this module.

#15

System Message - March 28, 2009 - 16:10
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.