You are here

protected function AutosaveEntityFormDatabaseStorage::serializeEntity in Autosave Form 8

Returns the serialized entity object.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity object to serialize.

\Drupal\Core\Form\FormStateInterface $form_state: The form state to retrieve meta information about the serialization.

Return value

string The serialized entity.

1 call to AutosaveEntityFormDatabaseStorage::serializeEntity()
AutosaveEntityFormDatabaseStorage::storeEntityAndFormState in src/Storage/AutosaveEntityFormDatabaseStorage.php
Stores the entity together with the form state.

File

src/Storage/AutosaveEntityFormDatabaseStorage.php, line 299

Class

AutosaveEntityFormDatabaseStorage
A database backend for autosave of entity forms.

Namespace

Drupal\autosave_form\Storage

Code

protected function serializeEntity(EntityInterface $entity, FormStateInterface $form_state) {
  if (($form_object = $form_state
    ->getFormObject()) && $form_object instanceof ContentEntityFormInterface && method_exists($form_object, 'isEntityDeepSerializationRequired') && $form_object
    ->isEntityDeepSerializationRequired()) {

    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    if (method_exists($entity, 'setDeepSerialization')) {
      $entity
        ->setDeepSerialization(TRUE);
    }
  }
  return $this->serializer
    ->encode($entity);
}