从Drupal 7的“内容类型"字段中检索列表 [英] Retrieving a list from Content Type field in Drupal 7

查看:50
本文介绍了从Drupal 7的“内容类型"字段中检索列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Drupal 7的新手.

I'm sort of new to Drupal 7.

我正在使用Drupal Form API,并且需要使用一个下拉列表,通过 mymodule_forms 挂钩显示状态列表.

I am using Drupal Form API and I need to use a drop-down showing a list of states via the mymodule_forms hook.

$form['work_state'] = array(
  '#title' => t('Work State'),
  '#type' => 'select',
  ...
);

我已经在内容类型"字段中定义了状态列表.

I already have a list of states defined in a Content Type field.

如何处理内容类型(即:forms_stipend)并检索字段(即:field_states).检索完之后,我可以开始将可用的状态列表填充到上面显示的代码中.

How would one go around loading the Content Type (ie: forms_stipend) and retrieving the field (ie: field_states). After that is retrieved, I can start populating the available list of states into the code shown above.

在此感谢您的帮助,总是!

推荐答案

假设您的字段是列表类型,则可以使用

Assuming your field is a list type, you can grab the allowed values from the field using the field_info_field() function:

$info = field_info_field('field_states');
$options = $info['settings']['allowed_values'];

$form['work_state'] = array(
  '#title' => t('Work State'),
  '#type' => 'select',
  '#options' => $options
);

这篇关于从Drupal 7的“内容类型"字段中检索列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆