开发者

Confused about theme function calls

开发者 https://www.devze.com 2022-12-26 19:44 出处:网络
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

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 hap开发者_如何学Pythonpen 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


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.


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'];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号