How can I set image weight for image nodes (image content type)?
I need the text of image node to go above the image, not below, can I use weight for it?

The image_attach module controls the weight of attached images in all other content types, but not within image nodes

Comments

mean0dspt’s picture

Category: support » bug

Ok, so I've investigated all the places I could think of and found no UI to control the weight of the image. So I'm changing this to bug report from support request

sun’s picture

Title: image weight in image content type » Allow to define image field weight in content-type
Version: 6.x-1.0-alpha4 » 6.x-1.x-dev
Category: bug » feature

Not really. This is a feature request. Patches are welcome.

sun’s picture

Marked another request as duplicate of this issue - which was related to Image Attach though. This means, both modules should expose their fields to CCK properly.

mean0dspt’s picture

CKK? I hope for this option to work on regular install, without CKK

sun’s picture

I do not think there is a way to change the order fields in a content-type without CCK. Since the core of CCK will be in Drupal 7, I am highly reluctant to add any overhead to Image module that is already covered by CCK - you can customize the output for image nodes in your theme.

sun’s picture

Status: Active » Needs work
+ * Implementation of hook_content_extra_fields.

Comments referring to functions should use braces after the function name. The trailing dot is kept.

+ * Implementation of hook_content_extra_fields.
+ * Lets CCK expose the image weight in the node content.

There should be a blank PHPDoc line between the summary and description. Let's strip "Lets CCK" in the description.

+    $extra = array();
+
+    $extra['image'] = array(

Array initialization is only needed for a) uninitialized, indexed arrays, ie. $extra[] (ie. no named or forced numeric array keys) and b) variables that need to be re-initialized. In this case, the initialization is not needed.

+    $extra = array();
+
+    $extra['image'] = array(
+      'label' => t('Image'),
+      'description' => t('Image display.'),
+      'weight' => 0,
+    );
+
+    return $extra;

With above ammendments removed, we don't need blank lines before and after the $extra array.

dman’s picture

Just IMO...

Array initialization is only needed for a) uninitialized, indexed arrays, ie. $extra[] (ie. no named or forced numeric array keys) and b) variables that need to be re-initialized. In this case, the initialization is not needed.

In the spirit of clear initializations, the pickyness of coder.module, and the sheer paranoia that E_NOTICE throws at us, I'd say that declaring an array before you use it is perfectly fine coding practice, and not something to be chastised for.
It's actually clearer code for maintainers, is at least as effective at highlighting minor code slip-ups as some other trivial complaints, and I actually would have expected E_NOTICE to justifiably complain about it. Well, as justifiably as it's other little moans are.

sun’s picture

@dman: Are you on the philosophical side of life again? :) Drupal core no longer initializes keyed arrays, e.g. in hook_menu() and other locations, so this has become a nice new standard, which obviously requires to know when it is ok to omit the initialization, but for such cases, it removes needless cruft.

dman’s picture

Oh yeah, it's not a sticking point at all, I was just interested in your opinion stated above.
Lots of other languages (and books) require or at least recommend declaring your vars. My take is that in PHP it doesn't hurt, saves scanning up to far to see what that array is all about, and is a useful place to drop in a comment.
Don't want to bikeshed it, but (IMO of course) it's not a bad thing to do.
But I always go for explicit code and don't worry too much about extra lines if it's clearer that way.

joachim’s picture

Status: Needs work » Needs review
StatusFileSize
new888 bytes

Patch for image module.
Lets you move the image field around with CCK.
Not that title, taxo, and menu fields are shown in CCK, but aren't controllable. You can move them, but it won't have any effect (there's a bug on CCK for this, though whether that's to lock them to prevent giving the illusion, or make them movable, I don't know.) So with this patch, you can move image in relation to body and any CCK fields you add.

sun’s picture

Status: Needs review » Needs work

@joachim: Seems like this is the old patch? Did you see the review for it in #6? Sorry, duplicate issue hell.

joachim’s picture

Ah, sorry, didn't get what that was about as there's no earlier patch -- is it about my patch? Oh I see...

> Comments referring to functions should use braces after the function name. The trailing dot is kept.
Fair enough, but I copied that line from CCK.

> Array initialization
Ditto.

joachim’s picture

Status: Needs work » Needs review
StatusFileSize
new738 bytes

new patch with your suggested changes.

> Let's strip "Lets CCK" in the description.
I disagree. It should be clear that this is a hook for CCK, not core.

sun’s picture

StatusFileSize
new20.9 KB

This works pretty good, but we have one caveat: The image thumbnail and "Rebuild derivative images" checkbox is still output at the top of the node add/edit form. (see attached screenshot)

joachim’s picture

As discussed on IRC, I've grouped the image-related fields together: thumbnail, upload field, regenerate checkbox.
They can be grouped with an anonymous array, but if we want to be able to style them too, easiest thing is to give them a fieldset.
Exposing this fieldset to CCK allows moving the whole of it in the CCK UI.

sun’s picture

Status: Needs review » Reviewed & tested by the community

Nice! Now it works as intended.

There's just one remaining thing that bugs me now: Usually we use fieldsets for multiple value fields only, but we will only ever allow the user to upload one image into an image node. I'm especially considering this regarding Image Assist, which, with this patch: #386298: Simplify the upload form, patch attached (screenshot), renders the absolute minimum of the image node form. So I wonder whether we shouldn't use #prefix and #suffix instead, as discussed in IRC.

But then again, I'm not 100% sure, so I defer this decision to you.

joachim’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new3.06 KB

Given that the image is an essential part of an image node, there's a case to be made for having it outside of fieldsets like the other essential element (title and body).

I prefer to avoid HTML in forms where possible, but #attributes don't work on markup types despite the docs saying so: http://drupal.org/node/424180 :(

So let's go with #prefix and #suffix.

sun’s picture

Status: Needs review » Fixed

Fixed changelog entry, white-space on blank lines, one wrong indentation, and committed. Thanks!

Status: Fixed » Closed (fixed)

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