Problem/Motivation
Im trying to use entity_autocomplete_tagify in a multistep form, but if I take the contents of the form field and feed this into default_value,
example of what im trying to put into default_value
[@"value":"11","entity_id":11,"info_label":null,"label":"Website Development","editable":false,"input":"we"]
TypeError: Drupal\Core\Entity\EntityRepository::getTranslationFromContext(): Argument #1 ($entity) must be of type Drupal\Core\Entity\EntityInterface, string given, called in /var/www/sites/drupal/multisite/web/modules/contrib/tagify/src/Element/EntityAutocompleteTagify.php on line 247 in Drupal\Core\Entity\EntityRepository->getTranslationFromContext() (line 94 of /var/www/sites/drupal/multisite/web/core/lib/Drupal/Core/Entity/EntityRepository.php).
To help me get through this a working example prepopulating the field would help, I thought even
$default_value[] = [
'value' => 11,
'label' => 'Web development',
'entity_id' => 11,
'info_label' => '',
'editable' => FALSE
];
would work, but no joy. any help would be very welcome.
Steps to reproduce
$terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadMultiple([11, 7]);
$default_tags = [];
foreach ($terms as $term) {
$default_tags[] = ['value' => $term->label(), 'entity_id' => $term->id()];
}
$form['sector'] = [
'#type' => 'entity_autocomplete_tagify',
'#target_type' => 'taxonomy_term',
'#default_value' => $default_tags,
'#title' => $this->t('What industry sectors are your business in'),
'#required' => TRUE,
'#tags' => TRUE,
'#selection_handler' => 'default',
'#selection_settings' => [
'target_bundles' => ['sector'],
'bundle' => ('sector'),
'info_label' => '',
],
'#autocreate' => [
'bundle' => 'sector',
],
'#description' => $this->t('Order from most to least important to your business (max 5)'),
'#wrapper_attributes' => [
'id' => 'odt-filter',
'class' => ['container-inline'],
],
'#max_items' => 5,
'#suggestions_dropdown' => 1,
'#match_operator' => 'CONTAINS',
'#show_entity_id' => 0,
];
$logger->info($this->store->get('sector'));