You are here

public static function ResaveBatch::batchOperation in Automatic Entity Label 8.3

{@inheritdoc }

File

src/Batch/ResaveBatch.php, line 20

Class

ResaveBatch
Processes entities in chunks to re-save their labels.

Namespace

Drupal\auto_entitylabel\Batch

Code

public static function batchOperation(array $chunk, array $bundle, array &$context) {
  foreach ($chunk as $id) {
    $entity = '';
    switch ($bundle[0]) {
      case 'node':
        $entity = Node::load($id);
        break;
      case 'taxonomy_term':
        $entity = Term::load($id);
        break;
      case 'media':
        $entity = Media::load($id);
        break;
      case 'comment':
        $entity = Comment::load($id);
        break;
    }
    $entity
      ->save();
    $context['results'][] = $id;
  }
}