You are here

public function Watermark::batchFinished in Media watermark 8

Perform tasks when a batch is complete.

Callback for batch_set().

Parameters

bool $success: A boolean indicating whether the batch operation successfully concluded.

int $results: The results from the batch process.

array $operations: The batch operations that remained unprocessed. Only relevant if $success is FALSE.

File

src/Watermark/Watermark.php, line 231

Class

Watermark
Custom watermark class.

Namespace

Drupal\media_watermark\Watermark

Code

public function batchFinished(bool $success, int $results, array $operations) {

  // TODO: find way to use batch finish function from class.
  $messenger = \Drupal::messenger();
  if ($success) {
    $count = count($results);
    $messenger
      ->addStatus(t('Added watermarks to @count images.', [
      '@count' => $count,
    ]));
    $messenger
      ->addMessage(t('Also has been flushed image styles generated for updated images. If images still seems to be same as before, please flush your browser cache.'));
  }
  else {

    // An error occurred.
    // $operations contains the operations that remained unprocessed.
    $error_operation = reset($operations);
    $messenger
      ->addError(t('An error occurred while processing @operation with arguments : @args', [
      '@operation' => $error_operation[0],
      '@args' => print_r($error_operation[0], TRUE),
    ]));
  }
}