I have a drupal content type called "Event", and I'd like to create a Drupal module that retrieves data from an api and uses that data to populate a set of options in a dropdown form field on the editing interface for "Event".
I have two questions:
$option_terms = taxonomy_get_tree(VID_OF_THE_TAXONOMY_VOCAB);
$options = array();
foreach ($option_terms as $option_term) {
$options[$option_term->tid] = $option_term->name;
}
$form['dropdown_field_name'] = array(
'#type' => 'select',
'#title' => t('The dropdown'),
'#options' => $options,
);
Getting data from an API and storing it - Presumably there is an external endpoint you will get this JSON from. So you want to make an HTTP request there to grab it probably. So I would look at drupal_http_request. As for storing it you may wish to store it in the database so you will want to have a table created that can accept the data and then obviously put it there with SQL. It really depends on the data... maybe it would be good to use taxonomy, it depends...
You will want to use hook_form() and then create a dropdown field. For example if you stored the options for the dropdown in a Drupal taxonomy, you could generate the "array of options" based on the code at the top here.