EDIT2:
as requested by @sonfd, my batch API code:
$fileId = $form_state->getValue('file_to_import')[0];
$file = File::load($fileId);
$filename = $file->filename->value;
$members = file('sites/default/files/_private/' . $filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$file->delete();
$temp = array_shift($members);
$operations = [];
foreach ($members as $member) {
$operations[] = ['\Drupal\association\Form\MemberImportStatus::updateMember', [$member]];
}
$batch = [
'operations' => $operations,
'title' => t('Members Status Import'),
'init_message' => t('Members status import is starting.'),
'progress_message' => t('Processed @current out of @total. Estimated time: @estimate.'),
'error_message' => t('The importation process has encountered an error.'),
'finished' => '\Drupal\association\Form\MemberImportStatus::end_of_update',
];
batch_set($batch);
with an example of input file:
id;status;enddate
104;0;2014-12-31
205;0;2014-12-31
400;0;2014-12-31
and the code for operation:
public static function updateMember($member, &$context)
{
$aTemp = explode(";", $member);
$storage = \Drupal::entityTypeManager()->getStorage('member');
$member = $storage->load($aTemp[0]);
if ($member) {
$member->set("status", $aTemp[1]);
$member->set("enddate", $aTemp[2]);
$member->save();
$context['results'][] = $aTemp[0];
$context['message'] = t('Updating status for member @id', array('@id' => $aTemp[0]));
}
}
The purpose is to "mass"-update the entity (one member per batch operation).
The View that outputs results as a csv file is triggered by hook_entity, the same way it is when I update the entity thru CRUD form...