我不想从字段中获取任何信息,我只想获取附加到特定捆绑包(实体的实例)的字段计算机名称。
我正在研究entityfieldquery、entity_load和entity_get_info,并且我倾向于使用entity_get_info,但现在我发现use已被弃用。
function multi_reg_bundle_select() {
$query = entity_get_info('registration');
}如何从附加的捆绑包中获取信息?(‘注册’‘bundlename’‘)?最终,我只想将字段附加到一个特定的包中。优选地,在字符串数组中。
发布于 2015-01-16 21:42:50
你可以在https://drupal.stackexchange.com/questions/14352/listing-entity-fields上找到答案
简短的回答:使用
$fields = field_info_instances();要获取有关所有实体类型和包的所有信息,请使用
$fields = field_info_instances('node', 'article');若要仅获取节点的字段,请键入“文章”。
发布于 2016-02-02 08:37:59
仅将字段计算机名称附加到特定捆绑包的最简单方法是:
$field_names = array_keys(field_info_instances('node', 'article'));使用前面提到的函数;在某些情况下,field_info_instances()的一个缺点是它不提供字段类型。在Drupal7中,最轻量级的函数是field_info_field_map()。它可以放在一个助手函数中,如下所示:
/**
* Helper function to return all fields of one type on one bundle.
*/
function fields_by_type_by_bundle($entity_type, $bundle, $type) {
$chosen_fields = array();
$fields = field_info_field_map();
foreach ($fields as $field => $info) {
if ($info['type'] == $type &&
in_array($entity_type, array_keys($info['bundles'])) &&
in_array($bundle, $info['bundles'][$entity_type]))
{
$chosen_fields[$field] = $field;
}
}
return $chosen_fields;
}并像这样使用它,以获取文章内容类型上的所有分类字段:
$fields = fields_by_type_by_bundle('node', 'article', 'taxonomy_term_reference');注意,field_info_field_map()只给出了机器名(正如最初的发帖所请求的那样),但是您必须用field_info_field()加载字段对象才能获得字段标签(人类可读的名称)。
发布于 2013-08-13 01:02:00
我相信field_info_bundles()可能就是我要找的。当我测试过它时,我会让人们知道(但是,如果您有建议,我很高兴听到它们!)
https://api.drupal.org/api/drupal/modules!field!field.info.inc/function/field_info_bundles/7
https://stackoverflow.com/questions/18192579
复制相似问题