I'm attempting to allow users to enter a number of node types in an entity reference field inside a custom config form. However I can't seem to supply it with a proper default value. My field in the form looks like this:
$config = $this->config('contentform.settings');
$form['content_types'] = [
'#type' => 'entity_autocomplete',
'#description' => t('Choose what content types to map'),
'#target_type' => 'node_type',
'#default_value' => $config->get('content_type'),
];
However $config->get('content_type') only supplies me with the label of the content type.
So I get the following error
InvalidArgumentException: The #default_value property has to be an entity object or an array of entity objects
I'm saving the value in the submit function like so:
$content_type = $form_state->getValue('content_types');
$this->config('contentform.settings')
->set('content_type', $content_type)
->save();
I've also tried $form_state->get('content_types') and $form_state->get('content_types')->entity; But those didn't work either.
How would I get the node_type entity or object instead of just the label? Or is there a way to load the node_type from just the name?