You are here

private function LayoutBuilderMigration::buildBatch in Panelizer 8.5

Builds a batch definition for a migration to Layout Builder.

Parameters

\Drupal\layout_builder\Entity\LayoutEntityDisplayInterface $display: The entity view display to migrate.

Return value

\Drupal\Core\Batch\BatchBuilder The batch definition.

File

src/LayoutBuilderMigration.php, line 265

Class

LayoutBuilderMigration
Provides functionality to migrate Panelizer data to Layout Builder.

Namespace

Drupal\panelizer

Code

private function buildBatch(LayoutEntityDisplayInterface $display) {
  $batch = new BatchBuilder();

  // Migrate the Panelizer data in the view display first. Once that's done,
  // entity-specific data can be migrated.
  $batch
    ->addOperation([
    static::class,
    'processDisplay',
  ], (array) $display
    ->id());
  $entity_type = $this->entityTypeManager
    ->getDefinition($display
    ->getTargetEntityTypeId());
  $storage = $this->entityTypeManager
    ->getStorage($entity_type
    ->id());
  $query = $storage
    ->getQuery()
    ->exists('panelizer')
    ->condition('panelizer.view_mode', 'full');
  if ($entity_type
    ->hasKey('bundle')) {
    $query
      ->condition($entity_type
      ->getKey('bundle'), $display
      ->getTargetBundle());
  }
  if ($entity_type
    ->isRevisionable()) {
    $query
      ->allRevisions();
  }

  // If the query is looking for revisions, the array keys will be revision
  // IDs. In any event, the array keys are always the canonical ID of the
  // thing we want to migrate.
  foreach (array_keys($query
    ->execute()) as $entity_id) {
    $batch
      ->addOperation([
      static::class,
      'processEntity',
    ], [
      $entity_type
        ->id(),
      $entity_id,
    ]);
  }
  return $batch;
}