Drupal 8  8.0.2
EntityForm Class Reference
Inheritance diagram for EntityForm:

Public Member Functions

 setOperation ($operation)
 
 getBaseFormId ()
 
 getFormId ()
 
 buildForm (array $form, FormStateInterface $form_state)
 
 form (array $form, FormStateInterface $form_state)
 
 processForm ($element, FormStateInterface $form_state, $form)
 
 afterBuild (array $element, FormStateInterface $form_state)
 
 submitForm (array &$form, FormStateInterface $form_state)
 
 save (array $form, FormStateInterface $form_state)
 
 buildEntity (array $form, FormStateInterface $form_state)
 
 getEntity ()
 
 setEntity (EntityInterface $entity)
 
 getEntityFromRouteMatch (RouteMatchInterface $route_match, $entity_type_id)
 
 getOperation ()
 
 setModuleHandler (ModuleHandlerInterface $module_handler)
 
 setEntityManager (EntityManagerInterface $entity_manager)
 
 setEntityTypeManager (EntityTypeManagerInterface $entity_type_manager)
 
- Public Member Functions inherited from EntityFormInterface
 setStringTranslation (TranslationInterface $string_translation)
 
- Public Member Functions inherited from FormInterface
 validateForm (array &$form, FormStateInterface $form_state)
 

Protected Member Functions

 init (FormStateInterface $form_state)
 
 actionsElement (array $form, FormStateInterface $form_state)
 
 actions (array $form, FormStateInterface $form_state)
 
 copyFormValuesToEntity (EntityInterface $entity, array $form, FormStateInterface $form_state)
 
 prepareEntity ()
 
 prepareInvokeAll ($hook, FormStateInterface $form_state)
 

Protected Attributes

 $operation
 
 $moduleHandler
 
 $entityManager
 
 $entityTypeManager
 
 $entity
 

Detailed Description

Base class for entity forms.

Member Function Documentation

actions ( array  $form,
FormStateInterface  $form_state 
)
protected

Returns an array of supported actions for the current entity form.

Todo:
Consider introducing a 'preview' action here, since it is used by many entity types.

References t().

Referenced by EntityForm\actionsElement().

Here is the call graph for this function:

Here is the caller graph for this function:

actionsElement ( array  $form,
FormStateInterface  $form_state 
)
protected

Returns the action form element for the current entity form.

References EntityForm\actions(), and Element\children().

Referenced by EntityForm\buildForm().

Here is the call graph for this function:

Here is the caller graph for this function:

afterBuild ( array  $element,
FormStateInterface  $form_state 
)

Form element #after_build callback: Updates the entity with submitted data.

Updates the internal $this->entity object with submitted values when the form is being rebuilt (e.g. submitted via AJAX), so that subsequent processing (e.g. AJAX callbacks) can rely on it.

References EntityForm\buildEntity(), and FormStateInterface\isProcessingInput().

Here is the call graph for this function:

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.

See Also
::getEntity()
Parameters
array$formA nested array form elements comprising the form.
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form.
Returns
An updated copy of the form's entity object.
}

Implements EntityFormInterface.

References EntityForm\copyFormValuesToEntity().

Referenced by EntityForm\afterBuild(), EntityDisplayFormBase\multistepSubmit(), and EntityForm\submitForm().

Here is the call graph for this function:

Here is the caller graph for this function:

buildForm ( array  $form,
FormStateInterface  $form_state 
)

{Form constructor.

Parameters
array$formAn associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form.
Returns
array The form structure.
}

Implements FormInterface.

References EntityForm\actionsElement(), EntityForm\form(), FormStateInterface\has(), EntityForm\init(), and Drupal\service().

Here is the call graph for this function:

copyFormValuesToEntity ( EntityInterface  $entity,
array  $form,
FormStateInterface  $form_state 
)
protected

Copies top-level form values to entity properties

This should not change existing entity properties that are not being edited by this form.

Parameters
\Drupal\Core\Entity\EntityInterface$entityThe entity the current form should operate upon.
array$formA nested array of form elements comprising the form.
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form.

References FormStateInterface\getValues().

Referenced by EntityForm\buildEntity().

Here is the call graph for this function:

Here is the caller graph for this function:

form ( array  $form,
FormStateInterface  $form_state 
)

Gets the actual form array to be built.

See Also
::processForm()
::afterBuild()

Referenced by EntityForm\buildForm().

Here is the caller graph for this function:

getBaseFormId ( )

{Returns a string identifying the base form.

Returns
string|null The string identifying the base form or NULL if this is not a base form.
}

Implements BaseFormIdInterface.

References EntityForm\getFormId().

Here is the call graph for this function:

getEntity ( )

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

Returns
The current form entity.
}

Implements EntityFormInterface.

Referenced by EntityDeleteForm\buildForm(), BundleEntityFormBase\protectBundleIdElement(), and AccountForm\submitForm().

Here is the caller graph for this function:

getEntityFromRouteMatch ( RouteMatchInterface  $route_match,
  $entity_type_id 
)

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

Parameters
\Drupal\Core\Routing\RouteMatchInterface$route_matchThe route match.
string$entity_type_idThe entity type identifier.
Returns
The entity object as determined from the passed-in route match.
}

Implements EntityFormInterface.

References Drupal\entityManager(), RouteMatchInterface\getParameter(), and RouteMatchInterface\getRawParameter().

Here is the call graph for this function:

getFormId ( )

{Returns a unique string identifying the form.

Returns
string The unique string identifying the form.
}

Implements FormInterface.

Referenced by EntityForm\getBaseFormId().

Here is the caller graph for this function:

getOperation ( )

{Gets the operation identifying the form.

Returns
string The name of the operation.
}

Implements EntityFormInterface.

Referenced by ContentEntityForm\init().

Here is the caller graph for this function:

init ( FormStateInterface  $form_state)
protected

Initialize the form state and the entity before the first form build.

References EntityForm\prepareEntity(), EntityForm\prepareInvokeAll(), and FormStateInterface\set().

Referenced by EntityForm\buildForm().

Here is the call graph for this function:

Here is the caller graph for this function:

prepareEntity ( )
protected

Prepares the entity object before the form is built first.

Referenced by EntityForm\init().

Here is the caller graph for this function:

prepareInvokeAll (   $hook,
FormStateInterface  $form_state 
)
protected

Invokes the specified prepare hook variant.

Parameters
string$hookThe hook variant name.
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form.

References Drupal\moduleHandler().

Referenced by EntityForm\init().

Here is the call graph for this function:

Here is the caller graph for this function:

processForm (   $element,
FormStateInterface  $form_state,
  $form 
)

Process callback: assigns weights and hides extra fields.

See Also
::form()

References FormStateInterface\getFormObject().

Here is the call graph for this function:

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$formAn associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form.
Returns
int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.
}

Implements EntityFormInterface.

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 ::submit(), however this may be used to completely exchange the form entity, e.g. when preparing the rebuild of a multi-step form.

Parameters
\Drupal\Core\Entity\EntityInterface$entityThe entity the current form should operate upon.
Returns
$this
}

Implements EntityFormInterface.

setEntityManager ( EntityManagerInterface  $entity_manager)

{Sets the entity manager for this form.

Parameters
\Drupal\Core\Entity\EntityManagerInterface$entity_managerThe entity manager.
Returns
$this
Deprecated:
in Drupal 8.0.0, will be removed before Drupal 9.0.0.
Todo:
Remove this set call in https://www.drupal.org/node/2603542.
}

Implements EntityFormInterface.

References Drupal\entityManager().

Here is the call graph for this function:

setEntityTypeManager ( EntityTypeManagerInterface  $entity_type_manager)

{Sets the entity type manager for this form.

Parameters
\Drupal\Core\Entity\EntityTypeManagerInterface$entity_type_managerThe entity type manager.
Returns
$this
}

Implements EntityFormInterface.

References Drupal\entityTypeManager().

Here is the call graph for this function:

setModuleHandler ( ModuleHandlerInterface  $module_handler)

{Sets the module handler for this form.

Parameters
\Drupal\Core\Extension\ModuleHandlerInterface$module_handlerThe module handler.
Returns
$this
}

Implements EntityFormInterface.

References Drupal\moduleHandler().

Here is the call graph for this function:

setOperation (   $operation)

{Sets the operation for this form.

Parameters
string$operationThe name of the current operation.
Returns
$this
}

Implements EntityFormInterface.

submitForm ( array &  $form,
FormStateInterface  $form_state 
)

{Form submission handler.

Parameters
array$formAn associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form.
}

This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state can be updated, this way the subsequently invoked handlers can retrieve a regular entity object to act on. Generally this method should not be overridden unless the entity requires the same preparation for two actions, see for an example with the save and preview actions.

Parameters
array$formAn associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form.

Implements FormInterface.

References EntityForm\buildEntity(), and FormStateInterface\cleanValues().

Here is the call graph for this function:


The documentation for this class was generated from the following file: