我有一个表A的表A,参考表B。我希望我的表格与表A相关联,它的值将来自表B。我希望Select字段具有来自键值对的选项。表B

表A和表B都包含不同类型的实体。

我目前正在寻找使用实体参考的程序化解决方案,但不必从中添加一个新字段 Administration > Structure > <entity type>.

有帮助吗?

解决方案

我选择了使用的解决方案 entity_load 然后暂时将加载实体作为选项添加为选项:

$foreign_entity_items = entity_load('foreign_entity');
$foreign_entity_options = array();
foreach ($foreign_entity_items as $foreign_entity_item) {
    $foreign_entity_options[$foreign_entity_item->some_field] = $foreign_entity_item->some_other_field;
}

$form['some_form_element'] = array(
    '#title' => t('Some title'),
    '#type' => 'select',
    '#required' => TRUE,
    '#options' => $foreign_entity_options
);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top