You are here

public static function RoleBasedAccessSettingsBatch::batchFinishedCallback in Apigee Edge 8

Batch finished callback.

See also

callback_batch_finished()

File

modules/apigee_edge_apiproduct_rbac/src/RoleBasedAccessSettingsBatch.php, line 114

Class

RoleBasedAccessSettingsBatch
Utility function for API product RBAC settings save batch.

Namespace

Drupal\apigee_edge_apiproduct_rbac

Code

public static function batchFinishedCallback(bool $success, array $results, array $operations) {

  /** @var array $updated */
  $updated = $results['success'] ?? [];

  /** @var array $failed */
  $failed = $results['failed'] ?? [];
  if ($success && !empty($updated) && empty($failed)) {
    \Drupal::messenger()
      ->addStatus(t('All API product attributes have been updated successfully.'));
  }
  elseif (!empty($updated) || !empty($failed)) {
    if (!empty($updated)) {
      $items = [
        '#theme' => 'item_list',
        '#items' => $updated,
      ];
      $message = \Drupal::translation()
        ->formatPlural(count($updated), '@product API product successfully updated.', '@count API products successfully updated: @products.', [
        '@product' => reset($updated),
        '@products' => \Drupal::service('renderer')
          ->render($items),
      ]);
      \Drupal::messenger()
        ->addStatus($message);
    }
    if (!empty($failed)) {
      $items = [
        '#theme' => 'item_list',
        '#items' => $failed,
      ];
      $message = \Drupal::translation()
        ->formatPlural(count($failed), 'An API product failed failed: @product.', '@count API products could not be updated: @products.', [
        '@product' => reset($failed),
        '@products' => \Drupal::service('renderer')
          ->render($items),
      ]);
      \Drupal::messenger()
        ->addError($message);
    }
  }
  else {
    \Drupal::messenger()
      ->addStatus(t('No operation performed.'));
  }
}