interface EntityFormInterface implements BaseFormIdInterface (View source)

Defines an interface for entity form classes.

Methods

string
getFormId()

Returns a unique string identifying the form.

array
buildForm(array $form, FormStateInterface $form_state)

Form constructor.

validateForm(array $form, FormStateInterface $form_state)

Form validation handler.

submitForm(array $form, FormStateInterface $form_state)

Form submission handler.

string|null
getBaseFormId()

Returns a string identifying the base form.

$this
setOperation(string $operation)

Sets the operation for this form.

string
getOperation()

Gets the operation identifying the form.

getEntity()

Gets the form entity.

$this
setEntity(EntityInterface $entity)

Sets the form entity.

getEntityFromRouteMatch(RouteMatchInterface $route_match, string $entity_type_id)

Determines which entity will be used by this form from a RouteMatch object.

buildEntity(array $form, FormStateInterface $form_state)

Builds an updated entity object based upon the submitted form values.

int
save(array $form, FormStateInterface $form_state)

Form submission handler for the 'save' action.

$this
setStringTranslation(TranslationInterface $string_translation)

Sets the string translation service for this form.

$this
setModuleHandler(ModuleHandlerInterface $module_handler)

Sets the module handler for this form.

$this
setEntityTypeManager(EntityTypeManagerInterface $entity_type_manager)

Sets the entity type manager for this form.

Details

string getFormId()

Returns a unique string identifying the form.

The returned ID should be a unique string that can be a valid PHP function name, since it's used in hook implementation names such as hook_form_FORM_ID_alter().

Return Value

string

The unique string identifying the form.

array buildForm(array $form, FormStateInterface $form_state)

Form constructor.

Parameters

array $form

An associative array containing the structure of the form.

FormStateInterface $form_state

The current state of the form.

Return Value

array

The form structure.

validateForm(array $form, FormStateInterface $form_state)

Form validation handler.

Parameters

array $form

An associative array containing the structure of the form.

FormStateInterface $form_state

The current state of the form.

submitForm(array $form, FormStateInterface $form_state)

Form submission handler.

Parameters

array $form

An associative array containing the structure of the form.

FormStateInterface $form_state

The current state of the form.

string|null getBaseFormId()

Returns a string identifying the base form.

Return Value

string|null

The string identifying the base form or NULL if this is not a base form.

$this setOperation(string $operation)

Sets the operation for this form.

Parameters

string $operation

The name of the current operation.

Return Value

$this

string getOperation()

Gets the operation identifying the form.

Return Value

string

The name of the operation.

EntityInterface getEntity()

Gets the form entity.

The form entity which has been used for populating form element defaults.

Return Value

EntityInterface

The current form entity.

$this setEntity(EntityInterface $entity)

Sets the form entity.

Sets the form entity which will be used for populating form element defaults. Usually, the form entity gets updated by \Drupal\Core\Entity\EntityFormInterface::submit(), however this may be used to completely exchange the form entity, e.g. when preparing the rebuild of a multi-step form.

Parameters

EntityInterface $entity

The entity the current form should operate upon.

Return Value

$this

EntityInterface getEntityFromRouteMatch(RouteMatchInterface $route_match, string $entity_type_id)

Determines which entity will be used by this form from a RouteMatch object.

Parameters

RouteMatchInterface $route_match

The route match.

string $entity_type_id

The entity type identifier.

Return Value

EntityInterface

The entity object as determined from the passed-in route match.

EntityInterface buildEntity(array $form, FormStateInterface $form_state)

Builds an updated entity object based upon the submitted form values.

For building the updated entity object the form's entity is cloned and the submitted form values are copied to entity properties. The form's entity remains unchanged.

Parameters

array $form

A nested array form elements comprising the form.

FormStateInterface $form_state

The current state of the form.

Return Value

EntityInterface

An updated copy of the form's entity object.

See also

EntityFormInterface::getEntity

int save(array $form, FormStateInterface $form_state)

Form submission handler for the 'save' action.

Normally this method should be overridden to provide specific messages to the user and redirect the form after the entity has been saved.

Parameters

array $form

An associative array containing the structure of the form.

FormStateInterface $form_state

The current state of the form.

Return Value

int

Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.

$this setStringTranslation(TranslationInterface $string_translation)

Sets the string translation service for this form.

Parameters

TranslationInterface $string_translation

The translation manager.

Return Value

$this

$this setModuleHandler(ModuleHandlerInterface $module_handler)

Sets the module handler for this form.

Parameters

ModuleHandlerInterface $module_handler

The module handler.

Return Value

$this

$this setEntityTypeManager(EntityTypeManagerInterface $entity_type_manager)

Sets the entity type manager for this form.

Parameters

EntityTypeManagerInterface $entity_type_manager

The entity type manager.

Return Value

$this