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->entityTypeManager()
->getStorage('content_sharing')
->create([]);
$form = $this->entityTypeManager()
->getFormObject('content_sharing', 'custom_mode')
->setEntity($contentSharing);
$output['form'] = $this->formBuilder()->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?