Skip to content

Commit

Permalink
Issue #2994319 by Ramya Balasubramanian, mohrerao, virajrajankar, ben…
Browse files Browse the repository at this point in the history
…jamindamron, hardikpandya, kalyansamanta, jhodgdon, msankhala, jungle, kkalaskar, dhirendra.mishra, joachim, longwave, amateescu, mradcliffe, alexpott, jcnventura: EntityAutocomplete form element has no docs on how to use it

(cherry picked from commit 27b38859c5718732d89b956e7e75bda13898be71)
  • Loading branch information
catch committed Jul 31, 2020
1 parent fb90bbd commit cec0ef9
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions lib/Drupal/Core/Entity/Element/EntityAutocomplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,54 @@
/**
* Provides an entity autocomplete form element.
*
* The #default_value accepted by this element is either an entity object or an
* array of entity objects.
* The autocomplete form element allows users to select one or multiple
* entities, which can come from all or specific bundles of an entity type.
*
* Properties:
* - #target_type: (required) The ID of the target entity type.
* - #tags: (optional) TRUE if the element allows multiple selection. Defaults
* to FALSE.
* - #default_value: (optional) The default entity or an array of default
* entities, depending on the value of #tags.
* - #selection_handler: (optional) The plugin ID of the entity reference
* selection handler (a plugin of type EntityReferenceSelection). The default
* value is the lowest-weighted plugin that is compatible with #target_type.
* - #selection_settings: (optional) An array of settings for the selection
* handler. Settings for the default selection handler
* \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection are:
* - target_bundles: Array of bundles to allow (omit to allow all bundles).
* - sort: Array with 'field' and 'direction' keys, determining how results
* will be sorted. Defaults to unsorted.
* - #autocreate: (optional) Array of settings used to auto-create entities
* that do not exist (omit to not auto-create entities). Elements:
* - bundle: (required) Bundle to use for auto-created entities.
* - uid: User ID to use as the author of auto-created entities. Defaults to
* the current user.
* - #process_default_value: (optional) Set to FALSE if the #default_value
* property is processed and access checked elsewhere (such as by a Field API
* widget). Defaults to TRUE.
* - #validate_reference: (optional) Set to FALSE if validation of the selected
* entities is performed elsewhere. Defaults to TRUE.
*
* Usage example:
* @code
* $form['my_element'] = [
* '#type' => 'entity_autocomplete',
* '#target_type' => 'node',
* '#tags' => TRUE,
* '#default_value' => $node,
* '#selection_handler' => 'default',
* '#selection_settings' => [
* 'target_bundles' => ['article', 'page'],
* ],
* '#autocreate' => [
* 'bundle' => 'article',
* 'uid' => <a valid user ID>,
* ],
* ];
* @endcode
*
* @see \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection
*
* @FormElement("entity_autocomplete")
*/
Expand Down

0 comments on commit cec0ef9

Please sign in to comment.