I need to be able to reference or attach an image from a node, and display that image in the sidebar of the current page.

So far, the only solution I've found that lets me reference an image from a node without having to upload a new image for every node is the image module. But I can't see a way to make the attached image display in a block in the sidebar.

This issue leads me to believe that the capability exists in the 5.x branch:

http://drupal.org/node/113326

Is it possible in the 6.x branch?

Comments

escoles’s picture

Title: How to display images attached to current node in a block? » Attached Image block doesn't appear after initial install, until manual database edit
Category: support » bug

This seems to be a bug. See workaround posted here:

http://drupal.org/node/269225#comment-880496

On Drupal 6, after an initial install of image_attach, the block does not appear unless there is a value specified in the region field of the block's entry in the block table.

Manually editing the blocks table causes the block to appear.

If the block is subsequently disabled, it continues to be displayed on the Blocks page. You'll need to do a new clean install to see the problem.

joachim’s picture

Version: 6.x-1.0-alpha4 » 6.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new1.52 KB

Yup, looks like there's a problem here.
In D5, _block_rehash() set defaults for region etc.
In D6, it doesn't.
Furthermore, it assumes that if we set status, we set region too:

  $block['region'] = $block['status'] ? $block['region'] : BLOCK_REGION_NONE;

which is not unreasonable.

Given that attaching nodes show their attached images anyway, I don't see the point of having the block enabled too -- surely you only need it if you've hidden the attached image in the node.

So the best and quickest fix is to remove the status = 1.

As you've found, there's no way to get Drupal to notice the block once it's stored in the DB in this bad state. So I've added an update function to delete it. Next visit to the blocks admin page will restore it to the database.

Please test the attached patch -- try it on any installation of image, new or old, and run the update script.

joachim’s picture

StatusFileSize
new1.54 KB

On second thoughts, let's be sure to only delete that one block.
It may be that in the future this module has more blocks, and that a user only upgrades from the version before this fix to the version with more blocks in one go.

sp3boy’s picture

Hi, just came across this in the course of testing the block functionality of #81102: Attach Multiple Images with image_attach using Drupal upload mechanism. The above patch in #3 works fine in making the attached images block accessible on the admin/build/blocks page.

I agree that the benefit of having a block for the attached images of a node that is already being displayed with its attached images may not be immediately obvious (I've never used it myself). However the block can display different size images from the main node layout. If #81102: Attach Multiple Images with image_attach using Drupal upload mechanism is committed, allowing multiple attached images, the Attached Image block could be a "short cut" to allow users to call up full-size versions of the image (particularly with Lightbox2 automatic handling installed) while the node display is showing Preview size. Or something like that.

By the way it looks like #81102: Attach Multiple Images with image_attach using Drupal upload mechanism also has an update function image_attach_update_6101(). Testing the above patch with #81102 already applied, I had to change the function name. I guess whichever issue is committed first gets ownership!

joachim’s picture

Well I'd say this patch is ready to go, so should get the 6101, but image attach is a monster we really want to get sorted once and for all.
I'd rather re-roll this one than that one, so let's postpone this until #81102: Attach Multiple Images with image_attach using Drupal upload mechanism lands.

joachim’s picture

Status: Needs review » Fixed

On second thoughts, let's get patches IN!

Committed:

#426724 by joachim: Fixed image attach block not showing in block admin.

rsvelko’s picture

Status: Fixed » Needs review

as said in another issue here: the right patch would be either:
DELETE FROM {blocks} blocks WHERE blocks.module = 'image_attach' AND blocks.delta = 0

or

DELETE FROM {blocks} WHERE module = 'image_attach' AND delta = 0

joachim’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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