LinkAutocompleteFormTrait
Provides helpers for adding a content autocomplete link element to a form.
- Full name:
\Drupal\helper\LinkAutocompleteFormTrait
Methods
getLinkAutocompleteElement
Generates an autocomplete link element for a form.
public static getLinkAutocompleteElement(string $entity_type, string $default_value = null): array
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$entity_type |
string | |
| The entity type. | ||
$default_value |
string | |
| The default value for the field. |
Return Value:
The autocomplete link form element.
validateLinkAutocompleteElement
Validation callback for URL elements.
public static validateLinkAutocompleteElement(mixed& $element, \Drupal\Core\Form\FormStateInterface $form_state): mixed
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$element |
mixed | |
$form_state |
\Drupal\Core\Form\FormStateInterface |
getUriAsDisplayableString
Gets the URI without the 'internal:' or 'entity:' scheme.
protected static getUriAsDisplayableString(string $uri): string
The following two forms of URIs are transformed: - 'entity:' URIs: to entity autocomplete ("label (entity id)") strings; - 'internal:' URIs: the scheme is stripped.
This method is the inverse of ::getUserEnteredStringAsUri().
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$uri |
string | |
| The URI to get the displayable string for. |
Return Value:
The displayable string.
See Also:
- \Drupal\helper\static::getUserEnteredStringAsUri()
- \Drupal\link\Plugin\Field\FieldWidget\LinkWidget::getUriAsDisplayableString()
getUserEnteredStringAsUri
Gets the user-entered string as a URI.
protected static getUserEnteredStringAsUri(string $entity_type, string $string): string
The following two forms of input are mapped to URIs: - entity autocomplete ("label (entity id)") strings: to 'entity:' URIs; - strings without a detectable scheme: to 'internal:' URIs.
This method is the inverse of ::getUriAsDisplayableString().
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$entity_type |
string | |
| The entity type. | ||
$string |
string | |
| The user-entered string. |
Return Value:
The URI, if a non-empty $uri was passed.
See Also:
- \Drupal\helper\static::getUriAsDisplayableString()
- \Drupal\link\Plugin\Field\FieldWidget\LinkWidget::getUserEnteredStringAsUri()