Overview
Formats
This module doesn't define any new formats.
Widgets
This module doesn't define any new widgets.
Fields
link
This module provides a link
field that behaves similarly to Drupal's core link field. To use this field in the uiSchema set the field link
AND add the link
$filter to your field's schema definition. For more information on the available configuration options read the definitions below.
Filters
link
This filter adds support for backend validation of autocompleted values and validates typed in urls as well.
Supported types
- object
$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"
}
}
uiSchema
Hiding URL or Title field
The title and url fields both support the standard approach for being hidden with RJSF.
{
"uiSchema":{
"link":{
"ui:field":"link",
"title":{
"ui:widget":"hidden"
},
"url":{
"ui:widget":"hidden"
}
}
}
}
Examples
Single link
{
"schema":{
"title":"Example single value link field",
"type":"object",
"properties":{
"link":{
"title":"Link",
"type":"object",
"properties":{
"url":{
"type":"string"
},
"entity":{
"type":"object"
},
"title":{
"type":"string"
}
},
"$filters":{
"$func":"link",
"$vars":{
"target_type":"node",
"handler":"default",
"handler_settings":{
"target_bundles":null,
"sort":{
"field":"_none",
"direction":"ASC"
}
}
}
}
}
}
},
"uiSchema":{
"link":{
"ui:field":"link"
}
}
}
Required URL
{
"schema":{
"title":"Example single value link field",
"type":"object",
"properties":{
"link":{
"title":"Link",
"type":"object",
"required":[
"url"
],
"properties":{
"url":{
"type":"string"
},
"entity":{
"type":"object"
},
"title":{
"type":"string"
}
},
"$filters":{
"$func":"link",
"$vars":{
"target_type":"node",
"handler":"default",
"handler_settings":{
"target_bundles":null,
"sort":{
"field":"_none",
"direction":"ASC"
}
}
}
}
}
}
},
"uiSchema":{
"link":{
"ui:field":"link"
}
}
}
Required title
{
"schema":{
"title":"Example single value link field",
"type":"object",
"properties":{
"link":{
"title":"Link",
"type":"object",
"required":[
"title"
],
"properties":{
"url":{
"type":"string"
},
"entity":{
"type":"object"
},
"title":{
"type":"string"
}
},
"$filters":{
"$func":"link",
"$vars":{
"target_type":"node",
"handler":"default",
"handler_settings":{
"target_bundles":null,
"sort":{
"field":"_none",
"direction":"ASC"
}
}
}
}
}
}
},
"uiSchema":{
"link":{
"ui:field":"link"
}
}
}
Multiple links
{
"schema":{
"title":"Example multiple link fields",
"type":"object",
"properties":{
"links":{
"title":"Links",
"type":"array",
"maxItems":5,
"items":{
"type":"object",
"properties":{
"url":{
"type":"string"
},
"entity":{
"type":"object"
},
"title":{
"type":"string"
}
},
"$filters":{
"$func":"link",
"$vars":{
"target_type":"node",
"handler":"default",
"handler_settings":{
"target_bundles":null,
"sort":{
"field":"_none",
"direction":"ASC"
}
}
}
}
}
}
}
},
"uiSchema":{
"links":{
"items":{
"ui:field":"link"
}
}
}
}