How can I programmatically create a select input whose values come from a foreign key using Form API?
I went with this solution that uses entity_load then adding the loaded entities as options to the select field for now:

$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-&gt;some_field] = $foreign_entity_item-&gt;some_other_field;
}

$form['some_form_element'] = array(
    '#title' =&gt; t('Some title'),
    '#type' =&gt; 'select',
    '#required' =&gt; TRUE,
    '#options' =&gt; $foreign_entity_options
);