I have a text file which is a list of 100s of rows. Which I am trying to turn in to a select list.
I have created a module, in mymodule/src/form/mymoduleform.php. I am trying to load the items from the file and turn the file content into an array which can be used as options for the form element.
The form element is created by the following code.
$form['mymodule_select'] = [
'#type' => 'select',
'#title' => $this->t('Select element'),
'#options' => selectlist_options(),
];
selectlist_options()
is implemented using the following code.
function selectlist_options() {
$options = [];
$result = file('options.txt');
foreach ($result as $key => $value) {
$options[$key] = $options['name'];
}
return $options;
}
Is this the correct approach?