views:

140

answers:

3

I've created a content type that has a CCK text field.

When I select the text field using the Drupal Themer widget it tells me the last function called was theme_text_formatter_default() , which I found in the CCK text.module

It also tells me that it's parents were;

content-field.tpl.php < theme_markup < theme_markup < node.tpl.php < page.tpl.php

So I assumed that somewhere in the content-field.tpl.php was the function call to theme('text_formatter_default',$element) but it wasn't in there. Just print $item['view'] used to display the content.

I searched all the project files for theme('text_formatter_default',$element) and it doesn't exist. I know it's being called by the theme function as I override it in my template.php and it used my overridden function, which would only happen if was using the theme_hook$. Wouldn't it?

So how is it being called? It's not that I need to override it. I'm just learning how drupal works and thought I had it sussed until this. Something must be calling it.

Also, the function theme_text_formatter_default exists in the theme registry and it's overridable (if that's a word) as I did so in my template.php and it displayed. It's all quite confusing.

Any help would be much appreciated

+1  A: 

It's CCK that calls the theming function.

When you create a CCK field you select a widget. The widget corresponds to a theming function that is called. That's the short explaination.

To understand the entire mechanics will be a bit difficult as creating a cck field is a complex subject lacking good documentation.

To really understand what, how and why, you would need to understand how the CCK module works internally. Probably to the point where you could write patches for it. Something very few people could help you with.

Edit:
I don't know the CCK module in depth, I have only created my own field formatters. Anyways, I looked though the db and found that the table content_node_field_instance holds info about each CCK field, one of the columns is widget which it seems, is where CCK stores which theming function to call. It knows what function to call because if the naming convention that is used and through the implementation of hook_field_formatter_info, which is what other modules uses when they want to tell CCK about how to theme a field.

googletorp
Hi Googletorp. I'm getting the impression there's little about Drupal you don't know as you've answered almost all my Drupal questions. I understand what you've said and I that there's not much good documentation but if it OK I would just like to ask one more question (which is posted below this).
Nick Lowman
I'm still not sure why I can't find the calling function. Using Eclipse I searched every file inside my Drupal project (including modules) for the string `text_formatter_default` but it only came back with two places in the text.module, where it was registered with theme_hook and the implementation. No calling function anywhere? Is that because the function name for `text_formatter_default` is created dynamically somewhere in the CCK module before being called so it wouldn't exist?
Nick Lowman
Thanks Googletorp. As always I'm grateful for your help.
Nick Lowman
A: 

Would you be able to post your example function calling theme_text_formatter_default ?

Stinky
A: 

The function is defined in text.module. the theme function that matches the entry text_formatter_default returned from the implementation of hook_theme()istheme_text_formatter_default()`.

/**
 * Theme function for 'default' text field formatter.
 */
function theme_text_formatter_default($element) {
  return ($allowed =_text_allowed_values($element)) ? $allowed : $element['#item']['safe'];
}
kiamlaluno

related questions