public function EntityUsageBatchManager::generateBatch in Entity Usage 8.2
Create a batch to process the entity types in bulk.
Return value
array The batch array.
1 call to EntityUsageBatchManager::generateBatch()
- EntityUsageBatchManager::recreate in src/
EntityUsageBatchManager.php - Recreate the entity usage statistics.
File
- src/
EntityUsageBatchManager.php, line 85
Class
- EntityUsageBatchManager
- Manages Entity Usage integration with Batch API.
Namespace
Drupal\entity_usageCode
public function generateBatch() {
$operations = [];
$to_track = $to_track = $this->config
->get('track_enabled_source_entity_types');
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type_id => $entity_type) {
// Only look for entities enabled for tracking on the settings form.
$track_this_entity_type = FALSE;
if (!is_array($to_track) && $entity_type
->entityClassImplements('\\Drupal\\Core\\Entity\\ContentEntityInterface')) {
// When no settings are defined, track all content entities by default,
// except for Files and Users.
if (!in_array($entity_type_id, [
'file',
'user',
])) {
$track_this_entity_type = TRUE;
}
}
elseif (is_array($to_track) && in_array($entity_type_id, $to_track, TRUE)) {
$track_this_entity_type = TRUE;
}
if ($track_this_entity_type) {
$operations[] = [
'\\Drupal\\entity_usage\\EntityUsageBatchManager::updateSourcesBatchWorker',
[
$entity_type_id,
],
];
}
}
$batch = [
'operations' => $operations,
'finished' => '\\Drupal\\entity_usage\\EntityUsageBatchManager::batchFinished',
'title' => $this
->t('Updating entity usage statistics.'),
'progress_message' => $this
->t('Processed @current of @total entity types.'),
'error_message' => $this
->t('This batch encountered an error.'),
];
return $batch;
}