Phoenix enters the red planet, and Imagefield gets sortable images!

This patch adds a form field to each uploaded image that allows users to sort images by weight.

Do I have to say more, other than awesome!?

Since this is a result of a joint work, please credit also smk-ka when committing this.

CommentFileSizeAuthor
imagefield-DRUPAL-5--2.sort_.patch3.79 KBsun
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sun’s picture

Version: 6.x-3.x-dev » 5.x-2.1

Actually, this patch is against DRUPAL-5--2.

Drag'n'drop sorting via jQuery UI is a separate patch: #264171: Use jQuery UI for drag'n'drop sorting of images

dopry’s picture

Status: Needs review » Needs work

Why not do the weight sort in hook_field just before the deltas are compressed?

sun’s picture

Good catch. However, we need to re-sort already existing images upon uploading a new one. Otherwise, a user may alter the weights of existing images, upload a new image, and find previously defined weights reset.

dopry’s picture

seems like as along as the weight is set on a new upload the ordering will happen in form table properly. We only need to save this data in hook_field.. you do know hook_field is called from within nodeapi....

The only reason you should be using nodeapi instead of hook_field with field data is to circumvent the order in which hooks are called naturally by content.module re: content default implementations and field implementations. This is not a case in which you need to shortcut that behavior.

.darrel.

canen’s picture

Sub.

drasgardian’s picture

I agree. "awesome!". Well done and thanks.

solutiondrop’s picture

I just tried this patch and it works for up to 11 images. The first image is assigned a weight of 0 and the next image is assigned a 1, etc. When you reach the 12th upload the weight is assigned as -10 and then the 13th image is also assigned a -10. Is there a way to allow the weight to go beyond 10?
Thanks!

muhleder’s picture

Couple of pages on increasing the weight limit beyond the default of 10 here

http://drupal.org/node/117274

http://drupal.org/node/68823

Would be nice to work out how do this in this patch just for the imagefield module.

onelittleant’s picture

If you want to handle more than 10 images, you can add a '#delta' attribute to the weight form element. There's a section of this patch that looks like this:

+        if ($field['multiple']) {
+          $form[$fieldname][$delta]['weight'] = array(
+            '#type' => 'weight',
+            '#title' => t('Weight'),
+            '#default_value' => $delta,
+          );
+        }

make it look like this (for 100 images):

+        if ($field['multiple']) {
+          $form[$fieldname][$delta]['weight'] = array(
+            '#type' => 'weight',
+            '#title' => t('Weight'),
+            '#default_value' => $delta,
+            '#delta' => 100
+          );
+        }

apologies... not a patch master...

THANK YOU ALL! I've been looking for this for a while.

SocialNicheGuru’s picture

YOU GUYS AND GALS ARE SOOOOO FLIPPING AWESOME! (ok enough with the caps). This is really really really really great. it makes things very easy.

momper’s picture

great - thanks a lot ...

Sansui’s picture

You are awesome, I just wanted you to know that. This was perfect for our Ubercart installs - it wasn't so hot being unable to change the main image! This is simple, but perfect - thanks again so much!

camb416’s picture

@onelittleant

I tried exactly as you said, but got this error message...

patching file imagefield.module
Hunk #1 succeeded at 629 (offset 14 lines).
patch: **** malformed patch at line 32:            '#title' => t('Delete'),

Any advice would be very much appreciated...

ricardo37’s picture

I got the same result as camb416. I fixed the problem by removing the extra line of patch code recommended to allow sorting for >10 images. I added that line manually to the imagefield.module file once the patch was successfully completed using the original patch file.

aterchin’s picture

subscribe

quicksketch’s picture

Status: Needs work » Closed (won't fix)

Time to move on to Drupal 6. I'm marking this won't fix as it's built into Drupal 6 and likely to break ImageField in some way or another.