Basefield 'string' shown as select list widget in entity form I've got a custom entity ('content_sharing') and defined one of the fields as $fields['entity_definition'] = BaseFieldDefinition::create('string').... The create-form I'm showing the user is loaded with an empty entity via a controller like so:

    $contentSharing = $this-&gt;entityTypeManager()
      -&gt;getStorage('content_sharing')
      -&gt;create([]);
    $form = $this-&gt;entityTypeManager()
      -&gt;getFormObject('content_sharing', 'custom_mode')
      -&gt;setEntity($contentSharing);
    $output['form'] = $this-&gt;formBuilder()-&gt;getForm($form);
    ...


What I need now is to present the user a select-list of possible strings (options) that are dynamically pre-populated everytime the form is loaded. The only FieldWidget for string fields is a textfield. I tried to come up with my own custom FieldWidget similar to this

 * @FieldWidget(
 *   id = "string_select_list",
 *   module = "content_sharing",
 *   label = @Translation("Select list for strings"),
 *   field_types = {
 *     "string"
 *   },
 *  multiple_values = FALSE
 * )
 */

class StringSelectList extends OptionsWidgetBase {


However, this resulted in an error and I  noticed that this needs to have options defined which I cannot (don't know how to) provide for my string basefield.

I could of cource just add a dummy form-element select list that provides the values for my entity field, but I wanted to use the entityform as it is without any further custom elements.

Possible with a custom widget or any other solutions?
Create a list_string base field and use as widget OptionsSelectWidget.

$fields['entity_definition'] = BaseFieldDefinition::create('list_string')
  -&gt;setLabel(t('Entity Definition'))
  -&gt;setSettings([
    'allowed_values' =&gt; [
      'value1' =&gt; 'Value 1',
      'value2' =&gt; 'Value 2',
    ],
  ])
  -&gt;setDisplayOptions('form', [
    'type' =&gt; 'options_select',
  ])


To update the options dynamically add a callback to the base field settings allowed_values_function, see How do I programmatically update the allowed values of a list field?