BatchService.php in Taxonomy Entity Index 8        
                          
                  
                        
  
  
  
  
  
File
  src/BatchService.php
  
    View source  
  <?php
namespace Drupal\taxonomy_entity_index;
class BatchService {
  
  public function processEntityTypeReindex($batch_id, $entity_type, $entity_id, &$context) {
    $context['results'][] = $batch_id;
    $context['message'] = t('Running Batch @batch_id: type: @entity_type - id: @entity_id', [
      '@batch_id' => $batch_id,
      '@entity_type' => $entity_type,
      '@entity_id' => $entity_id,
    ]);
    $entity = \Drupal::entityTypeManager()
      ->getStorage($entity_type)
      ->load($entity_id);
    taxonomy_entity_index_entity_update($entity);
  }
  
  public function processEntityTypeReindexFinished($success, array $results, array $operations) {
    $messenger = \Drupal::messenger();
    if ($success) {
      
      $messenger
        ->addMessage(t('@count results processed.', [
        '@count' => count($results),
      ]));
    }
    else {
      
      $error_operation = reset($operations);
      $messenger
        ->addMessage(t('An error occurred while processing @operation with arguments : @args', [
        '@operation' => $error_operation[0],
        '@args' => print_r($error_operation[0], TRUE),
      ]));
    }
  }
}