对主题函数调用感到困惑

发布于 2024-08-28 13:54:30 字数 897 浏览 7 评论 0原文

我创建了一个具有 CCK 文本字段的内容类型。

当我使用 Drupal Themer 小部件 选择文本字段时,它告诉我最后调用的函数是 theme_text_formatter_default() ,我在 CCK text.module 中找到它,

它还告诉我它的父母是;

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

所以我假设 content-field.tpl.php 中的某个地方是对 theme('text_formatter_default',$element) 的函数调用,但它并不在那里。只需 print $item['view'] 用于显示内容。

我在所有项目文件中搜索了 theme('text_formatter_default',$element) 但它不存在。我知道它是由 theme 函数调用的,因为我在 template.php 中重写了它,并且它使用了我重写的函数,只有在使用 theme_hook$ 时才会发生这种情况。不是吗?

那么它是怎么称呼的呢?这并不是说我需要覆盖它。我刚刚学习 drupal 是如何工作的,并且认为我已经把它搞定了。一定有什么东西在召唤它。

另外,函数 theme_text_formatter_default 存在于主题注册表中,并且它是可重写的(如果这是一个单词),就像我在 template.php 中所做的那样并显示出来。这一切都很令人困惑。

任何帮助将不胜感激

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

始终不够爱げ你 2024-09-04 13:54:30

调用主题功能的是CCK。

当您创建 CCK 字段时,您选择一个小部件。该小部件对应于被调用的主题函数。这就是简短的解释。

要理解整个机制会有点困难,因为创建 cck 字段是一个复杂的主题,缺乏良好的文档。

要真正理解什么、如何以及为什么,您需要了解 CCK 模块的内部工作原理。可能到了可以为它编写补丁的程度。很少有人可以帮助你的事情。

编辑:
我不深入了解 CCK 模块,我只创建了自己的字段格式化程序。无论如何,我查看了数据库,发现表 content_node_field_instance 保存有关每个 CCK 字段的信息,其中一列是 widget ,它似乎是 CCK 存储哪个主题的地方要调用的函数。它知道要调用什么函数,因为如果使用命名约定并通过实现hook_field_formatter_info,这是其他模块在想要告诉CCK如何主题化字段时使用的。

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.

走过海棠暮 2024-09-04 13:54:30

该函数在 text.module 中定义。与 hook_theme() 实现返回的条目 text_formatter_default 匹配的主题函数theme_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'];
}

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'];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文