Skip to content

Drupal\helper\EntityBrowserFormTrait

Provides helpers for adding an entity browser element to a form.

Methods

Name Description
getEntityBrowserForm Adds the Entity Browser element to a form.
getEntityBrowserValue Gets the entity browser form value.
loadEntityBrowserEntitiesByIds Loads entities based on an ID in the format entity_type:entity_id.
loadEntityBrowserEntity Loads entity based on an ID in the format entity_type:entity_id.
processEntityBrowser Render API callback: Processes the entity browser element.
processEntityBrowserSelected Render API callback: Processes the table element.
updateEntityBrowserSelected AJAX callback: Re-renders the Entity Browser button/table.

EntityBrowserFormTrait::getEntityBrowserForm

Description

public static getEntityBrowserForm (string $entity_browser_id, string $default_value, int $cardinality, string $view_mode, string|bool $form_mode)

Adds the Entity Browser element to a form.

Parameters

  • (string) $entity_browser_id : The ID of the entity browser to use.
  • (string) $default_value : The default value for the entity browser.
  • (int) $cardinality : The cardinality of the entity browser.
  • (string) $view_mode : The view mode to use when displaying the selected entity in the table.
  • (string|bool) $form_mode : 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 Values

array

The form element containing the entity browser.


EntityBrowserFormTrait::getEntityBrowserValue

Description

public static getEntityBrowserValue (\Drupal\Core\Form\FormStateInterface $form_state, array|string $parents)

Gets the entity browser form value.

Parameters

  • (\Drupal\Core\Form\FormStateInterface) $form_state : The form state.
  • (array|string) $parents : The parents of the containing form element.

Return Values

array

The entity browser value.


EntityBrowserFormTrait::loadEntityBrowserEntitiesByIds

Description

public static loadEntityBrowserEntitiesByIds (array|string $ids)

Loads entities based on an ID in the format entity_type:entity_id.

Parameters

  • (array|string) $ids : An array of IDs.

Return Values

\Drupal\Core\Entity\EntityInterface[]

An array of loaded entities, keyed by an ID.


EntityBrowserFormTrait::loadEntityBrowserEntity

Description

public static loadEntityBrowserEntity (string $id)

Loads entity based on an ID in the format entity_type:entity_id.

Parameters

  • (string) $id : An ID.

Return Values

\Drupal\Core\Entity\EntityInterface

A loaded entity.


EntityBrowserFormTrait::processEntityBrowser

Description

public static processEntityBrowser (void)

Render API callback: Processes the entity browser element.

Parameters

This function has no parameters.

Return Values

void


EntityBrowserFormTrait::processEntityBrowserSelected

Description

public static processEntityBrowserSelected (void)

Render API callback: Processes the table element.

Parameters

This function has no parameters.

Return Values

void


EntityBrowserFormTrait::updateEntityBrowserSelected

Description

public static updateEntityBrowserSelected (void)

AJAX callback: Re-renders the Entity Browser button/table.

Parameters

This function has no parameters.

Return Values

void