I'd like to be able to customize the display of iTweak Upload's rendered attachments, from code in a separate module. For example, if the filename has a certain extension, I'd like to show the file content using Lightbox2 rel="lightmodal".
Currently it doesn't look like there's any way to alter iTweak Upload's rendered output (aside from hacking the theme registry and using regexes to replace text in the already-rendered attachment list, which I'd really like to avoid doing).
The attached patch adds a call to drupal_alter() just prior to adding a row for each attachment, thus enabling other modules to implement hook_itweak_uploads_prerender_alter(&$data) to further tweak the uploads.
What do you think? Any chance this patch could be committed?
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | itweak_upload_alter-1253692-9.patch | 1.57 KB | jonathan_hunt |
| #4 | itweak_upload_alter-02.patch | 618 bytes | smokris |
| #2 | itweak_upload_alter-01.patch | 1015 bytes | smokris |
| itweak_upload_alter.patch | 586 bytes | smokris |
Comments
Comment #1
iva2k commentedI don't see a principal problem with this patch, so yes, it can be committed in my opinion. I have a plan to go over the queue in a week or so, will commit at that time.
Comment #2
smokrisGreat. Thanks, iva2k.
I discovered an issue with my patch in the meantime: need to undo modifications to $options each time around the attachment loop, else when another module makes a change for one file on a node, that change will be applied to all future files on that node. Revised patch attached.
Comment #3
iva2k commentedYou must've worked off a quite old 6.x-2.x-dev code. I checked your patch, and it won't apply to the latest. I gather that it would be in itweak_upload_upload_attachments() function, but logic around $options has changed significantly - it now is pulled from each file's record. Can you reroll the patch against the latest code? Alternatively, itweak_upload_upload_attachments() is a theme function that was intended to be overridden, so you may be better off doing a custom theme instead of a hook.
Comment #4
smokrisOh, sorry, I think the above patch was against 6.x-2.4, not 6.x-2.x-dev. New patch attached; this time against 6.x-2.x-dev.
Comment #5
iva2k commented@smokris
Thanks, that's good!
Before I add it to 6.x-2.x-dev though, I want you to answer the following question:
itweak_upload_upload_attachments() is a theme function that was intended to be overridden. Did you try doing a custom theme instead of a hook?
Comment #6
smokrisI did, and it works, but doing it that way seems unnecessarily redundant.
With this hook, I can (for example) write a module with 5 lines of code to cause certain types of attachments to be shown in a lightbox. And the hook can also be used by other modules to alter the rendering of certain other attachments in different ways. Modular and extensible.
Without this hook, I'd need to duplicate the 67-line itweak_upload_upload_attachments() function to make this minor change, and then I'd have to manually merge any future changes made to the function in itweak_upload.module into my clone of it. And other modules wouldn't be able to make further changes without obliterating mine by overriding the theme function again.
IMO an alteration hook seems like a more elegant solution.
Comment #7
iva2k commentedOk, makes sense. Committed.
Comment #9
jonathan_hunt commentedThis hook has proved very useful to me, but it could be better placed in the code. The attached patch moves the hook to before any table row output is created. Otherwise the hook allows external modules to change the attachment link but not the attachment preview.
Comment #10
iva2k commentedSorry for the delay. I've copied the latest patch to my sandbox, will commit soon. I noticed a type "itweak_uploads_prerender" should be "itweak_upload_prerender" for naming consistency.
Comment #11
iva2k commentedIn D7 version I renamed the hook to 'itweak_upload_file_link_prerender' and moved it (due to a complete rewrite) to theme_file_link_itu() (which I think I will rename later to theme_itweak_upload_file_link for naming consistency, I keep it to remind its resemblance to theme_file_link() for now).
You may want to review the code in 7.x-3.x-dev as the hook may need to be moved higher in the loop too. The problem is that the variables it wants to operate on are only present in theme_file_link_itu(). I think it can be resolved if I save these variables (options, link_text, url) in the file object, but need your input. ANd if it moves, the hook may need to be renamed again, hook_itweak_upload_file_prerender() seems more appropriate.
Comment #13
cmstomThanks for adding drupal_alter, I was able to implement my own hook. This was essential to allowing node attachments to ability to open in a new window. I'm simply posting a thank you and an example of how I used it.
Open Atrium 1.x (Drupal 6) uses the iTweaks Upload module, so it was necessary for me to use a hook to alter the attributes in order to open attachments in a new window. I created a simple module that hooks into the iTweaks Upload hook.
My .module file: