我有很少的节点类型,其中一些有一个额外的字段链接到分类词汇表。我如何获得分类词汇表id或名称,如果我知道该字段存在的字段名称和节点类型?我如何通过node_type得到分类词汇表
1
A
回答
2
在Drupal 7的字段可以被添加到任何实体/束,以及用于长期参考领域中使用的词汇表上的实体/束水平设置现场级,不。
因此,您不需要查询特定内容类型的字段设置,而只需查询字段本身的设置。词汇机器名称都存储在settings
阵列的allowed_values
重点从field_info_field()
返回:
$field_name = 'field_name_of_field';
$info = field_info_field($field_name);
$vocab_keys = array();
foreach ($info['settings']['allowed_values'] as $item) {
$vocab_keys[] = $item['vocabulary'];
}
// $vocab_keys now contains an array of all vocabulary machine names allowed on this field
希望帮助
0
如果您在额外领域中保留术语,此代码很有用。
/**
* Get vocabulary ID by term name applied to node
*/
$tid = $node->your_field[$node->language][0]['tid'];
$term = taxonomy_term_load($tid);
/* $term now is the following object
stdClass Object(
[tid] => 1
[vid] => 1
[name] => Name of term
[description] => Description of term
[format] => full_html
[weight] => 0
[vocabulary_machine_name] => vocabulary
) */
/**
* Loading vocabularies
*/
$vocabularies = taxonomy_get_vocabularies();
/* $vocabularies now is the following array
Array(
[1] => stdClass Object(
[vid] => 1
[name] => Forums
[machine_name] => forums
[description] => Forum navigation vocabulary
[hierarchy] => 1
[module] => forum
[weight] => -10
)
[2] => stdClass Object(
[vid] => 2
[name] => Category
[machine_name] => category
[description] =>
[hierarchy] => 1
[module] => taxonomy
[weight] => -9
)
) */
/**
* Vocabulary searched by you
*/
$vocabulary = $vocabularies[$term->vid];
/* $vocabulary now is the following object
Array(
[1] => stdClass Object(
[vid] => 1
[name] => Forums
[machine_name] => forums
[description] => Forum navigation vocabulary
[hierarchy] => 1
[module] => forum
[weight] => -10
)
) */
相关问题
- 1. 通过名称获得词汇表
- 2. 通过网络管理Plone词汇表
- 3. Drupal分类标准块,词汇表
- 4. Drupal6x:来自同一分类词汇表
- 5. 空的词汇通过CountVectorizer
- 6. Drupal:从分类词汇词汇创建分层菜单
- 7. 如何检查分类词汇表何时更改Drupal 7
- 8. 如何通过日期获得汇率?
- 9. 如何从两个词汇表生成Drupal分类标准Breadcrumbs?
- 10. 过滤词汇表视图
- 11. 词汇表的词法分析
- 12. 通过小型词汇进行词汇封闭?
- 13. 如何通过TF/IDF得分获得文档中的单词列表
- 14. drupal 7 - 按分类词汇分组
- 15. 如何分解冗长的词汇,但忽略短词汇?
- 16. 潜在迪里克莱特分配如何处理词汇不在词汇表
- 17. 如何通过分组得到年龄分布列表
- 18. 如何通过jquery得到父类型
- 19. 我如何得到这个:通过?
- 20. 如何使用JAWS插件获得wordNet词汇类别(名词类别和动词类别)
- 21. PHP如何区分上下文中的词汇类型
- 22. 通过汇总到HTML表中的多级分组
- 23. 设置词汇列表的PHP OO类
- 24. 如何建立一个词汇表
- 25. 如何处理deezer ID词汇表
- 26. 如何在给定单词的单词袋词汇中获得单词的id?
- 27. 通过API以其他语言进行词汇表
- 28. 如何通过单词列表增加?
- 29. 如何通过谓词LINQ表达
- 30. 如何使用视图在Drupal 7上显示2级分类词汇列表
酷! Thx共享关于'field_info_field'函数=) – 2011-12-23 16:20:24
@ VladStratulat:没问题:)如果你有兴趣,可以在'/ modules/field/field.info.inc'中找到大量有用的字段信息函数 – Clive 2011-12-23 16:24:38
优秀的解决方案,thnx ! – 2011-12-24 20:47:00