Hello Drupalers,
I feel I'm making a lot of headway into drupal theme and module development, but still have brain explosions when trying to follow best practices.
I have created a module that will display a node's listed attachments in a block in the sidebar.
Drupal's built in upload module is set-up to display these attachements at the bottom of $content in a node. And I want to remove it again.
line 270 of upload.module
function upload_nodeapi(&$node, $op, $teaser) {
switch ($op) {
.
.
.
case 'view':
if (isset($node->files) && user_access('view uploaded files')) {
// Add the attachments list to node body with a heavy
// weight to ensure they're below other elements
if (count($node->files)) {
if (!$teaser && user_access('view uploaded files')) {
$node->content['files'] = array(
'#value' => theme('upload_attachments', $node->files),
'#weight' => 50,
);
}
}
}
break;
I know I could create a node.tpl.php file removing $content and listing the required items, but wanting to improve my drupal skills and edit $content using a module or template.php. Ideally I remove the [files] from the $content in my custom module.
I hope that makes sense.
The code for my custom module (site_custom.module):
/*
* Implementation of hook_block()
*/
function site_custom_block ($op = 'list', $delta = '0', $edit = array()) {
switch ($op) {
case 'list' :
$blocks[0]['info'] = t('Attachments');
return $blocks;
case 'configure':
return;
case 'save':
return;
case 'view' :
$nid = print_r(arg(1), True);
$files = upload_load(node_load($nid));
$rows = array();
foreach ($files as $file) {
if ($file->list) {
$href = $file->fid ? file_create_url($file->filepath) : url(file_create_filename($file->filename, file_create_path()));
$text = $file->description ? $file->description : $file->filename;
$mime = strtoupper(substr($file->filemime, strrpos($file->filemime, '/')+1));
$header = array(t('Format'), t('File'), t('Size'));
$rows[] = array($mime, l($text, $href), format_size($file->filesize));
}
}
if (count($rows)) {
//$block['content'] = theme('table', $header, $rows, array('id' => 'attachments'));
$block['content'] = theme_table($header, $rows, array('id' => 'attachments'));
}
return $block;
}
}
And for a bonus point:
What's the difference between
What is the difference between:
$block['content'] = theme('table', $header, $rows, array('id' => 'attachments'));
and
$block['content'] = theme_table($header, $rows, array('id' => 'attachments'));
Comments
Try it.
First, I'm spanish and my english sucks... so maybe I don't uderstand as well as possible your question.
As my understanding, you should create a module and implement hook_alter or hook_nodeapi to remove there the files attribute from node content.