By stmh on
Hi,
I am looking for a way to extend the list of formatters of a given CCK-field without hacking the module itself. I want to create a custom module which extends the formatter-list of a CCk field.
To be more concrete:
I am using the filefield.module but I want a different display of the files within custom views. I can create a custom theme for the display but this will affect the display of all file-fields.
So my idea was to add a custom formatter to the filefield.module which I can intercept in my theming-function, but I don't want to hack the module itself to be as compatible as possible.
Or is there a simpler way to do what I want?
Thanks in advance
Stephan
Comments
subscribing
subscribing
subscribing
subscribing
Me too
I've been looking into this too. And I have yet to come up with anything. I'm no expert, but I'm starting to believe that it would have to be supported in the CCK framework in order for this to be possible.
Or as you said, hack the module. :(
Thomas G. Willis
filefield_display.module
Hacking the mediafield_display.module I ended up with this custom module that extend the filefields formatters. After installing the module two extra formatters are available. Plain Text and File Type Icon.
Plain Text simply returns the link to the file as plain text so that you can use it inside
<a>tags.File type icon requires to drop file type icons inside your_theme/images directory. These images must be named using the file extension (i.e. mov.png - mp3.png etc.).
The file type icon formatter displays an icon that links to the file.
Create two files:
and copy and paste the code below.
filefield_display.module
filefield_display.info
cck custom formatter hooks
As seen in the example filefield_display.module above, CCK actually provides two hooks to help you build custom field formatters: hook_field_formatter_info() and hook_field_formatter(). These are documented in an example included with CCK--check out lines 311 through 456 of cck/examples/example_field.php.
While making a custom formatter in Drupal 6 for FileField fields, I found that I could use hook_field_formatter_info() and a theme function, theme_hook_formatter_formatterName() (which I also had to mention in my module's hook_theme()). It looks something like this stub:
a small correction, now <?php
a small correction,
now
to
_
I know this is an old topic, but I just released a new module for exactly this purpose, adding custom formatters without the need of a custom module. It's aptly named Custom Formatters.