Overview
Formats
This module doesn't define any new formats.
Widgets
This module doesn't define any new widgets.
Fields
entity_autocomplete
This module provides an entity_autocomplete
field that behaves similarly to Drupal's core entity reference autocomplete fields. To use this field in the uiSchema set the field entity_autocomplete
AND add the entity_autocomplete
$filter to your field's schema definition. For more information on the available configuration options read the definitions below.
Filters
entity_autocomplete
This filter adds support for backend validation of values completed by the entity_autocomplete field.
Supported types
- array
$vars
target_type
The target entity type, i.e. node
.
"target_type":"node"
handler(optional)
The selection handler Drupal will use to
"handler":"default"
handler_settings(optional)
The configuration for the selection handler defined above. This should be the json version of the configuration settings defined by the handler. This can usually be located easily in yaml form by looking at Drupal config exports. Alternatively you can track down the selection handler's class to see all the options.
The default selection handler used by Drupal is \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection
which exports config looking like
handler_settings:
target_bundles:
page: page
article: article
sort:
field: _none
direction: asc
auto_create: false
auto_create_bundle: page
and in json form looks like
"handler_settings":{
"target_bundles":{
"page":"page",
"article":"article"
},
"sort":{
"field":"_none",
"direction":"ASC"
}
}
Examples
Single node reference
{
"schema":{
"properties":{
"exampleField":{
"title":"Node to reference",
"description":"Find the node you want to reference",
"type":"array",
"items":{
"type":"object"
},
"$filters":{
"$func":"entity_autocomplete",
"$vars":{
"target_type":"node",
"handler":"default",
"handler_settings":{
"target_bundles":null,
"sort":{
"field":"_none",
"direction":"ASC"
}
}
}
}
}
}
},
"uiSchema":{
"exampleField":{
"ui:field":"entity_autocomplete"
}
}
}
Multiple node reference
{
"schema":{
"properties":{
"example_multi":{
"title":"Multi example",
"description":"Example description",
"type":"array",
"maxItems":5,
"items":{
"type":"object"
},
"$filters":{
"$func":"entity_autocomplete",
"$vars":{
"target_type":"node",
"handler":"default",
"handler_settings":{
"target_bundles":null,
"sort":{
"field":"_none",
"direction":"ASC"
}
}
}
}
}
}
},
"uiSchema":{
"example_multi":{
"ui:field":"entity_autocomplete"
}
}
}