EntityBrowserFormTrait
Provides helpers for adding an entity browser element to a form.
- Full name:
\Drupal\helper\EntityBrowserFormTrait
Methods
getEntityBrowserForm
Adds the Entity Browser element to a form.
public static getEntityBrowserForm(string $entity_browser_id, string $default_value, int $cardinality = \Drupal\entity_browser\Element\EntityBrowserElement::CARDINALITY_UNLIMITED, string $view_mode = 'default', string|bool $form_mode = 'default'): array
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$entity_browser_id |
string | |
| The ID of the entity browser to use. | ||
$default_value |
string | |
| The default value for the entity browser. | ||
$cardinality |
int | |
| The cardinality of the entity browser. | ||
$view_mode |
string | |
| The view mode to use when displaying the selected entity in the table. | ||
$form_mode |
string|bool | |
| The form mode to use when showing the edit button for the selected | ||
| entity in the table. Use FALSE to disable the edit button. |
Return Value:
The form element containing the entity browser.
loadEntityBrowserEntity
Loads entity based on an ID in the format entity_type:entity_id.
public static loadEntityBrowserEntity(string $id): \Drupal\Core\Entity\EntityInterface
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$id |
string | |
| An ID. |
Return Value:
A loaded entity.
loadEntityBrowserEntitiesByIds
Loads entities based on an ID in the format entity_type:entity_id.
public static loadEntityBrowserEntitiesByIds(array|string $ids): \Drupal\Core\Entity\EntityInterface[]
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$ids |
array|string | |
| An array of IDs. |
Return Value:
An array of loaded entities, keyed by an ID.
getEntityBrowserValue
Gets the entity browser form value.
public static getEntityBrowserValue(\Drupal\Core\Form\FormStateInterface $form_state, array|string $parents): array
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$form_state |
\Drupal\Core\Form\FormStateInterface | |
| The form state. | ||
$parents |
array|string | |
| The parents of the containing form element. |
Return Value:
The entity browser value.
processEntityBrowser
Render API callback: Processes the entity browser element.
public static processEntityBrowser(mixed& $element, \Drupal\Core\Form\FormStateInterface $form_state, mixed& $complete_form): mixed
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$element |
mixed | |
$form_state |
\Drupal\Core\Form\FormStateInterface | |
$complete_form |
mixed |
processEntityBrowserSelected
Render API callback: Processes the table element.
public static processEntityBrowserSelected(mixed& $element, \Drupal\Core\Form\FormStateInterface $form_state, mixed& $complete_form): mixed
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$element |
mixed | |
$form_state |
\Drupal\Core\Form\FormStateInterface | |
$complete_form |
mixed |
updateEntityBrowserSelected
AJAX callback: Re-renders the Entity Browser button/table.
public static updateEntityBrowserSelected(array& $form, \Drupal\Core\Form\FormStateInterface $form_state): mixed
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$form |
array | |
$form_state |
\Drupal\Core\Form\FormStateInterface |