You are here

public function ContentExportForm::snapshot in Content Synchronization 8.2

Same name and namespace in other branches
  1. 3.0.x src/Form/ContentExportForm.php \Drupal\content_sync\Form\ContentExportForm::snapshot()

File

src/Form/ContentExportForm.php, line 106

Class

ContentExportForm
Defines the content export form.

Namespace

Drupal\content_sync\Form

Code

public function snapshot() {

  //Set batch operations by entity type/bundle
  $entities_list = [];
  $entity_type_definitions = $this->entityTypeManager
    ->getDefinitions();
  foreach ($entity_type_definitions as $entity_type => $definition) {
    $reflection = new \ReflectionClass($definition
      ->getClass());
    if ($reflection
      ->implementsInterface(ContentEntityInterface::class)) {
      $entities = $this->entityTypeManager
        ->getStorage($entity_type)
        ->getQuery()
        ->execute();
      foreach ($entities as $entity_id) {
        $entities_list[] = [
          'entity_type' => $entity_type,
          'entity_id' => $entity_id,
        ];
      }
    }
  }
  if (!empty($entities_list)) {
    $serializer_context['export_type'] = 'snapshot';
    $batch = $this
      ->generateExportBatch($entities_list, $serializer_context);
    batch_set($batch);
  }
}