简体   繁体   English

如何按Drupal中的内容类型列出CCK字段

[英]How to list CCK fields by content type in Drupal

To get a list of a content type's cck fields, I was hoping to use: 要获取内容类型的cck字段列表,我希望使用:

drupal_get_schema('content_type_mycontenttype');

but that leaves out fields with multiple values. 但是这会遗漏具有多个值的字段。 Is there a simple call to use to get such a list? 是否有一个简单的调用来获取这样的列表?

For Drupal 7, check out the field_info_instances function to retrieve a list of fields for a particular node content type. 对于Drupal 7,请查看field_info_instances函数以检索特定节点内容类型的字段列表。

Here is an example usage that will retrieve all the fields for a node content type. 以下是一个示例用法,它将检索节点内容类型的所有字段。

$my_content_type_fields = field_info_instances("node", "my_node_content_type"); $ my_content_type_fields = field_info_instances(“node”,“my_node_content_type”);

Take a look at the content_fields function, and if doesn't that have the information you need, there is _content_type_info . 看一下content_fields函数,如果没有你需要的信息,那就有_content_type_info

Additionally, once you have the field information, you can extract the table storage and column names using content_database_info . 此外,一旦获得字段信息,就可以使用content_database_info提取表存储和列名称。

I've used something like this before to do a quick list of CCK Field information for a content type: 我之前使用过这样的东西来快速列出内容类型的CCK字段信息:

    $mytype = 'article';
    $contentinfo = _content_type_info();
    $output .= "<ul>";
    foreach($contentinfo['fields'] as $field) {
        if ($field['type_name'] == $mytype) {
            $output .= '<li id="field-' . $field['field_name'] . '">' . $field['widget']['label'] . '<br>';

            if ($field['widget']['description']) {
                $output .= $field['widget']['description'] . '<br>';
            }    

            $output .= '<ul>
                    <li>Content Types: ' . $field['type_name'] . '</li>
                    <li>Type: ' . $field['type'] . '</li>
                    <li>' . $field['field_name'] . '</li>
                </ul>';
        }
    }
    $output .= '</ul>';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM