Created
August 10, 2012 16:45
-
-
Save rjpeter2/3315485 to your computer and use it in GitHub Desktop.
Overriding theme functions in a custom module.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Normally you would override theme function in your theme! However, if you want to | |
override something in the admin area where you are using an admin theme, you can do | |
the following */ | |
/** | |
* Implements hook_theme_registry_alter(). | |
*/ | |
function custom_theme_registry_alter(&$theme_registry) { | |
if (isset($theme_registry['file_link'])) { | |
$theme_registry['file_link']['function'] = 'custom_file_link'; | |
} | |
} | |
/** | |
* Implements theme_file_link(). | |
*/ | |
function custom_file_link($variables) { | |
$file = $variables['file']; | |
$icon_directory = $variables['icon_directory']; | |
$url = file_create_url($file->uri); | |
$icon = theme('file_icon', array('file' => $file, 'icon_directory' => $icon_directory)); | |
// Set options as per anchor format described at | |
// http://microformats.org/wiki/file-format-examples | |
$options = array( | |
'attributes' => array( | |
'type' => $file->filemime . '; length=' . $file->filesize, | |
), | |
); | |
return '<span class="file">' . $icon . ' ' . l($url, $url, $options) . '</span>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment