问题描述
我是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.
在此感谢您的帮助,总是!
推荐答案
假设您的字段是列表类型,则可以使用 field_info_field()
函数:
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的“内容类型"字段中检索列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!