Accessing field settings inside field formatter

crea - June 3, 2009 - 19:33
Project:Content Construction Kit (CCK)
Version:6.x-2.x-dev
Component:General
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

I'm in the process of making new field formatter. I need to access field settings to theme field output according to these settings. In 5.x this was easy. In 6.x we have theme functions instead of formatter function. hook_theme() has this:

arguments: (required) An array of arguments that this theme hook uses. This value allows the theme layer to properly utilize templates. The array keys represent the name of the variable, and the value will be used as the default value if not specified to the theme() function. These arguments must be in the same order that they will be given to the theme() function.

But, content_format() actually calls theme($theme, $element) without any additional arguments so $element is the only argument and we can't just plug in and provide additional variables to formatter theme function. Maybe add feature for modules to provide additional theme variables to formatter, like it was done with preprocess hooks ?
What is the best way to access field settings inside formatter function then ?

#1

crea - June 3, 2009 - 19:37

Hm, it is possible to modify field output in "sanitize" op of the hook_field of the custom module, before feeding it to content_format(). But this is ugly and works only when i'm in control of the module implementing this field.

#2

yched - June 3, 2009 - 21:04
Status:active» fixed

CCK sets the $element array contains the information you need to get the $field description.
See theme_text_formatter_trimmed() in text.module :
$field = content_fields($element['#field_name'], $element['#type_name']);

Note that the signature of formatter theme functions (single $element param) is imposed on us by the drupal_render() mechanism.

#3

crea - June 3, 2009 - 21:49

Hm, I hoped there would exist better way...but thanks anyway :)

#4

System Message - June 17, 2009 - 21:50
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.