Displaying a list of fields in a form select In a plugin's settings view, I'm looking to show a list of fields to choose from:

{% set fields = craft.fields.getAllFields() %}  

{{ forms.selectField({
    label:          'Salary Mapping'|t,
    id:             'broadbeanSalaryMapping',
    name:           'broadbeanSalaryMapping',
    instructions:   'Choose a field in which to store this value.'|t,
    value:          settings.broadbeanSalaryMapping,
    options:        fields,
    errors:         settings.getErrors('broadbeanSalaryMapping')
}) }}


However I get an error:


  Craft\FieldModel and its behaviors do not have a method or closure named "optgroup". 


Am I going about this the wrong way?
I've got a solution, though I'd be interested to know if there is a better way of doing it. In the plugin file:

public function getSettingsHtml()
{
    $options = [[
        'label' =&gt; 'Please select', 
        'value' =&gt; ''
    ]];

    foreach (craft()-&gt;fields-&gt;getAllFields() as $field)
    {
        $options[] = [
            'label' =&gt; $field['name'], 
            'value' =&gt; $field['handle']
        ];
    }

    return craft()-&gt;templates-&gt;render('broadbean/settings', array(
        'settings' =&gt; $this-&gt;getSettings(), 
        'options' =&gt; $options
    ));
}


And then in the settings template:

{{ forms.selectField({
    label:          'Salary Mapping'|t,
    id:             'broadbeanSalaryMapping',
    name:           'broadbeanSalaryMapping',
    instructions:   'Choose a field in which to store this value.'|t,
    value:          settings.broadbeanSalaryMapping,
    options:        options,
    errors:         settings.getErrors('broadbeanSalaryMapping')
}) }}