public function AutosaveEntityFormDatabaseStorage::storeEntityAndFormState in Autosave Form 8
Stores the entity together with the form state.
Parameters
string $form_id: The form id.
$form_session_id: The form session id.
string $entity_type_id: The entity type id of the entity to store.
mixed $entity_id: The id of the entity to store.
string $langcode: The language code of the original entity.
int $uid: The user id.
int $timestamp: The timestamp of the autosave.
\Drupal\Core\Entity\EntityInterface $entity: The entity object.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
Overrides AutosaveEntityFormStorageInterface::storeEntityAndFormState
File
- src/
Storage/ AutosaveEntityFormDatabaseStorage.php, line 48
Class
- AutosaveEntityFormDatabaseStorage
- A database backend for autosave of entity forms.
Namespace
Drupal\autosave_form\StorageCode
public function storeEntityAndFormState($form_id, $form_session_id, $entity_type_id, $entity_id, $langcode, $uid, $timestamp, EntityInterface $entity, FormStateInterface $form_state) {
$serialized_entity = $this
->serializeEntity($entity, $form_state);
$serialized_form_state = $this->serializer
->encode([
'storage' => $form_state
->getStorage(),
'input' => $form_state
->getUserInput(),
]);
if (!$entity
->isNew()) {
$this->connection
->insert(static::AUTOSAVE_ENTITY_FORM_TABLE)
->fields([
'form_id',
'form_session_id',
'entity_type_id',
'entity_id',
'langcode',
'uid',
'timestamp',
'entity',
'form_state',
])
->values([
$form_id,
$form_session_id,
$entity_type_id,
$entity_id,
$langcode,
$uid,
$timestamp,
$serialized_entity,
$serialized_form_state,
])
->execute();
}
}