public static function JsonapiBatchHelper::importEntityListBatch in Entity Share 8.2
Same name and namespace in other branches
- 8 modules/entity_share_client/src/JsonapiBatchHelper.php \Drupal\entity_share_client\JsonapiBatchHelper::importEntityListBatch()
Batch operation.
Parameters
\Drupal\entity_share_client\Entity\RemoteInterface $remote: The selected remote.
array $data: An array of data from a JSON:API endpoint.
array $context: Batch context information.
File
- modules/
entity_share_client/ src/ JsonapiBatchHelper.php, line 29
Class
- JsonapiBatchHelper
- Class JsonapiBatchHelper.
Namespace
Drupal\entity_share_clientCode
public static function importEntityListBatch(RemoteInterface $remote, array $data, array &$context) {
if (empty($context['sandbox'])) {
$context['sandbox']['progress'] = 0;
$context['sandbox']['max'] = count($data);
}
$limit = 10;
$sub_data = array_slice($data, $context['sandbox']['progress'], $limit);
/** @var \Drupal\entity_share_client\Service\JsonapiHelperInterface $jsonapi_helper */
$jsonapi_helper = \Drupal::service('entity_share_client.jsonapi_helper');
$jsonapi_helper
->setRemote($remote);
$result_ids = $jsonapi_helper
->importEntityListData($sub_data);
$context['results'] = array_merge($context['results'], $result_ids);
$context['sandbox']['progress'] += count($sub_data);
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}
}