You are here

public function QuickExportController::quickExport in Content Synchronizer 3.x

Same name and namespace in other branches
  1. 8.2 src/Controller/QuickExportController.php \Drupal\content_synchronizer\Controller\QuickExportController::quickExport()
  2. 8 src/Controller/QuickExportController.php \Drupal\content_synchronizer\Controller\QuickExportController::quickExport()

Launch quick export batch.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse THe response.

1 string reference to 'QuickExportController::quickExport'
content_synchronizer.routing.yml in ./content_synchronizer.routing.yml
content_synchronizer.routing.yml

File

src/Controller/QuickExportController.php, line 37

Class

QuickExportController
Class QuickExportController.

Namespace

Drupal\content_synchronizer\Controller

Code

public function quickExport(Request $request) {

  // Get the destination url.
  $this->url = $request->query
    ->has('destination') ? $request->query
    ->get('destination') : Url::fromRoute('system.admin_content')
    ->toString();
  if ($request->query
    ->has('entityTypeId') && $request->query
    ->has('entityId')) {

    /** @var \Drupal\Core\Entity\EntityInterface $entity */
    $entity = \Drupal::entityTypeManager()
      ->getStorage($request->query
      ->get('entityTypeId'))
      ->load($request->query
      ->get('entityId'));
    $writer = new ExportEntityWriter();
    $writer
      ->initFromId($entity
      ->getEntityTypeId() . '.' . $entity
      ->id());
    $batchExportProcessor = new BatchExportProcessor($writer);
    if ($entity instanceof ConfigEntityBundleBase) {
      $batchExportProcessor
        ->exportEntities(EntityExportFormBuilder::getEntitiesFromBundle($entity), [
        $this,
        'onBatchEnd',
      ]);
    }
    else {
      $batchExportProcessor
        ->exportEntities([
        $entity,
      ], [
        $this,
        'onBatchEnd',
      ]);
    }
    return batch_process('');
  }
  return new RedirectResponse($this->url);
}