Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I don't know exactly the policy regarding theming of core modules, but I think attachment list in upload.module should be themable. Here is a small patch to do so.
--- upload.module.orig 2005-05-22 10:23:58.784086137 +0200
+++ upload.module 2005-05-22 10:24:42.282575193 +0200
@@ -239,17 +239,13 @@
case 'view':
if ($node->files && user_access('view uploaded files')) {
- $header = array(t('Attachment'), t('Size'));
- $rows = array();
$previews = array();
+ $filelist = array();
// Build list of attached files
foreach ($node->files as $file) {
if ($file->list) {
- $rows[] = array(
- '<a href="/'. ($file->fid ? file_create_url($file->filepath) : url(file_create_filename($file->filename, file_create_path()))) . '">'. $file->filename .'</a>',
- format_size($file->filesize)
- );
+ $filelist[] = $file;
// We save the list of files still in preview for later
if (!$file->fid) {
$previews[] = $file;
@@ -273,8 +269,8 @@
$teaser = $arg;
// Add the attachments list
- if (count($rows) && !$teaser) {
- $node->body .= theme('table', $header, $rows, array('id' => 'attachments'));
+ if (count($filelist) && !$teaser) {
+ $node->body .= theme('node_attachments', $filelist);
}
}
break;
@@ -314,6 +310,18 @@
return $output;
}
+function theme_node_attachments($files) {
+ $header = array(t('Attachment'), t('Size'));
+ $rows = array();
+ foreach($files as $file) {
+ $rows[] = array(
+ '<a href="/'. ($file->fid ? file_create_url($file->filepath) : url(file_create_filename($file->filename, file_create_path()))) . '">'. $file->filename .'</a>',
+ format_size($file->filesize)
+ );
+ }
+ return theme('table', $header, $rows, array('id' => 'attachments'));
+}
+
function upload_count_size($uid = 0) {
if ($uid) {
$result = db_query("SELECT SUM(f.filesize) FROM {files} f INNER JOIN {node} n ON f.nid = n.nid WHERE uid = %d", $uid);
Comment | File | Size | Author |
---|---|---|---|
#15 | upload.module_36.patch | 1.25 KB | Zach Harkey |
#10 | upload.module_35.patch | 1.17 KB | Zach Harkey |
#7 | upload.module.diff.txt | 3.74 KB | drumm |
#6 | patch_34 | 3.73 KB | moshe weitzman |
#4 | 23373-4.7.patch.txt | 3.44 KB | Dave Cohen |
Comments
Comment #1
Zach Harkey CreditAttribution: Zach Harkey commented+1
Comment #2
Tobias Maier CreditAttribution: Tobias Maier commentedis this for 4.6 of head?
we only accept new feature in head and after 4.7
Comment #3
Veggieryan CreditAttribution: Veggieryan commentedcan we get this updated for 4.7b5?
thanks
ryan grace
Comment #4
Dave Cohen CreditAttribution: Dave Cohen commentedHere's my version for 4.7.
Comment #5
dopry CreditAttribution: dopry commentedI tested on 4.7rc1. The patch at the least doesn't break anything and enables an important feature for themers and site supporting media...
Now people can theme attachments according to extensions... I hope you can figure out what that means to the cunning themer....
Update version to 4.7rc1....
Comment #6
moshe weitzman CreditAttribution: moshe weitzman commentedi tested this patch and it works which is unsuprising since it just moves some HTML into a themeable function. I consider outputting raw HTML without themeability to be a bug.
rerolled for fuzz free
Comment #7
drummHere is a cleaned up version of this patch. I fixed indentation and made a couple comments more consistent (just because we are programmers doesn't mean we don't do proper english capitalization).
There is more code inside the check for clean URLs then before. I would like to make sure that this has been tested with clean URLs both on and off.
Comment #8
killes@www.drop.org CreditAttribution: killes@www.drop.org commentedtested and applied.
I've found a minor issue while testing, but it was unrelated.
Comment #9
killes@www.drop.org CreditAttribution: killes@www.drop.org commentedn
Comment #10
Zach Harkey CreditAttribution: Zach Harkey commentedWhile allows theming of the actual attachments table, the table is still forcibly and inflexibly appended to the node body.
This patch adds two additional theme functions: theme_upload_teaser() and theme_upload_body(). This convention, originally implemented in image.module, allows much greater flexibility with regard to how the attachment table relates to the node itself.
Possible uses (all actual cases):
I design themes for a lot of corporate and commercial websites and one of the things that I find most frustrating is when modules concatenate their output to the node body without leaving any way for me to separate them without resorting to hacks.
Comment #11
bradlis7 CreditAttribution: bradlis7 commentedOpening for discussion.
Comment #12
Dave Cohen CreditAttribution: Dave Cohen commentedWhile I have no problem with the concept, I think that
a) this could have been submitted as a new bug, and
2) your call to
$node->teaser = theme('upload_teaser', $node);
Is within an if clause that reads
if (count($node->files) && !$teaser)
I don't think this will properly handle the case when $teaser is true. (although it may appear to work for you, since you do nothing to the teaser).
Comment #13
Zach Harkey CreditAttribution: Zach Harkey commentedThat code is not part of the submitted patch, it's just an example of the kind of logic that would now be possible at the theme template level, In this particular case node-book.tpl.php — because for book nodes, I wanted to restrict the attachments table to the full view. I could just as easily add an else clause or move that check to somewhere else in the template entirely.
Comment #14
Zach Harkey CreditAttribution: Zach Harkey commentedWait — yogadex, I misread your comment. Now I see what you're saying and that is a good point. One that I will contemplate over a tasty beer.
Comment #15
Zach Harkey CreditAttribution: Zach Harkey commentedThis patch changes
if (count($node->files) && !$teaser)
to
if (count($node->files))
so it now works consistently in both teaser and body views.
I'm including this as part of this issue because I felt that while it wasn't really a new issue but more of an extension of the original issue. Then again, I'm still learning about how to contribute patches so if you guys want me to create a new issue I'd be glad to.
Comment #16
drummThis is the intended behavior, files aren't listed in teasers for standard themes, but a link is provided.
Comment #17
Zach Harkey CreditAttribution: Zach Harkey commentedYou can argue this being the intended behavior for teasers (although I don't see what's wrong with having this flexibility, I know I've needed it in the past), however the ability for theme designers to to separate the attachments table from the node->body is otherwise impossible.