Hello,
I am writing a module for adding a custom title on the file field.
I made a field and altered a form "publication_node_form" to show this field. The values from this field are stored into a custom table. My module can CRUD this table.
Function that shows the title is theme_file_link()
When I put this function on my template.php and call it MY_THEME_file_link() it works.
But I want to write it on my module in order to be generic and not depending on the theme.
I tried with hook_process_hook() but it does not works.
Do someone knows which hook I have to use or how otherwise I can override this theme_file_link() function?

Comments

Jaypan’s picture

Theme functions should not be overridden in modules, for two reasons:

1) The Drupal workflow is system -> module -> theme. Your proposed changes would be system -> module -> theme -> module, which doesn't fit in well with the workflow.

2) You can use hook_theme_registry_alter() to specify a file/template in your module that will override this, however it can then not be overridden in the theme (since it's always overridden in the module), breaking Drupal default functionality.

It's better to do in your theme.

vasko7vas’s picture

Dear Jaypan,

Thank you for your answer.

I will put my function into the theme.

Regards,
Vasko

krishnamohan_ramadugula’s picture

You can override theme_file_link function in your custom module by following way

function YOUR_THEME_file_link($variables) {
  //your manipulations 
return '<span class="file">' . $icon . ' ' . l($link_text, $url, $options) . '</span>';
}

I tried it and works well. Make sure to clear your cache after make these changes.