- Issue created by @stmh
- Assigned to gxleano
- last update
8 months ago 7 pass - last update
8 months ago 7 pass - last update
8 months ago 7 pass - last update
8 months ago 7 pass - last update
8 months ago 7 pass - 🇪🇸Spain gxleano Cáceres
Thank you, Stephan, for bringing up this topic.
I've refactored the Tagify element in order to facilitate the custom integration.
You could try to check if everything works fine for you with something like:
$form['user_reference'] = [ '#type' => 'entity_autocomplete_tagify', '#target_type' => 'user', '#title' => $this->t('Users'), '#attributes' => [ 'class' => ['user_reference'], ], ];
Or if you need to use attributes or so, follow the next example, please:
$form['my_element'] = [ '#type' => 'entity_autocomplete_tagify', '#target_type' => 'node', '#tags' => TRUE, '#default_value' => [['value' => 1, 'entity_id' => 1, 'label' => 'entity label']], '#selection_handler' => 'default', '#selection_settings' => [ 'target_bundles' => ['article', 'page'], 'info_label' => '[node:type]', ], '#autocreate' => [ 'bundle' => 'article', 'uid' => <a valid user ID>, ], '#max_items' => 10, '#suggestions_dropdown' => 1, '#match_operator' => 'CONTAINS', '#show_entity_id' => 0, '#identifier' => 'field_name', ];
I will document this part, when the issue will be reviewed.
- Issue was unassigned.
- Status changed to Needs review
8 months ago 11:35am 9 May 2024 - last update
8 months ago 7 pass - last update
8 months ago 7 pass - last update
8 months ago 7 pass - last update
8 months ago 7 pass - 🇪🇸Spain gxleano Cáceres
Demo from #7 ✨ Add support for custom form-element supporting entity_reference Needs review form example.
- 🇪🇸Spain gxleano Cáceres
If you also want to have current user as default value, you'd need to pass an array of entities to '#default_value', in this case with current:
$current_user = \Drupal::currentUser(); $uid = $current_user->id(); $current_user_entity = \Drupal::entityTypeManager()->getStorage('user')->load($uid); $form['user_reference'] = [ '#type' => 'entity_autocomplete_tagify', '#target_type' => 'user', '#title' => $this->t('Users'), '#description' => $this->t('Enter a user name.'), '#default_value' => [$current_user_entity], ];
- last update
8 months ago 7 pass - last update
8 months ago 7 pass - last update
8 months ago 7 pass - last update
8 months ago 7 pass - 🇱🇹Lithuania aliaric
I have an issue:
Code:$form['vocabulary_' . $category->tid] = [ '#title' => $this->t('You will add these tags'), '#prefix' => '<h2>' . $category->name . '</h2>', '#type' => 'entity_autocomplete_tagify', '#target_type' => 'taxonomy_term', '#tags' => TRUE, '#selection_handler' => 'default', '#selection_settings' => [ 'target_bundles' => ['tags'], 'bundle' => ('tags'), ], '#autocreate' => [ 'bundle' => 'tags', ], '#description' => $this->t('for all documents below simultaneously'), '#wrapper_attributes' => [ 'id' => 'odt-filter', 'class' => ['container-inline'], ], '#max_items' => 10, '#suggestions_dropdown' => 1, '#match_operator' => 'CONTAINS', '#show_entity_id' => 0, '#identifier' => 'vocabulary_' . $category->tid, ];
I'm not quite sure what '#identifier' is
version: '1.2.15+3-dev'
php: 8.1.27
drupal: 10.2.2
Errors:TypeError: preg_match(): Argument #2 ($subject) must be of type string, array given in preg_match() (line 207 of ... ...\core\lib\Drupal\Core\Routing\UrlGenerator.php).
and
Warning: Undefined array key "#placeholder" in Drupal\tagify\Element\EntityAutocompleteTagify::processEntityAutocompleteTagify() (line 152 of ...\modules\contrib\tagify\src\Element\EntityAutocompleteTagify.php)
- 🇪🇸Spain gxleano Cáceres
Hi @drebroff,
It's quite tricky to get this working in the current version of the module, for that reason Stephan created this "feature request" issue. Perhaps you could try forking this issue, where we are facilitating the creation of form elements with Tagify as a new feature.
Once the feature created in this issue is released, the creation of Tagify form elements will be much easier, as described in the comments.
- 🇪🇸Spain gxleano Cáceres
So, your example code should works as expected with this new feature.
BTW: The
#identifier
attribute is used to differentiate between multiple Tagify elements in a form. - last update
7 months ago 7 pass - First commit to issue fork.
- last update
7 months ago 7 pass - last update
7 months ago 7 pass - last update
7 months ago 7 pass - Status changed to Fixed
7 months ago 3:54pm 14 June 2024 - Status changed to Fixed
7 months ago 3:55pm 14 June 2024