public static function UpdateTerms::updateAllTerms in Termcase 8
Batch process callback.
Parameters
array $terms: The terms to update.
int $case: The case to convert the terms to.
array $context: Sandbox context.
File
- src/
UpdateTerms.php, line 20
Class
- UpdateTerms
- Class, which contains the callbacks of a batch process.
Namespace
Drupal\termcaseCode
public static function updateAllTerms(array $terms, $case, array &$context) {
if (!isset($context['sandbox']['progress'])) {
$context['sandbox']['progress'] = 0;
$context['sandbox']['current_term'] = 0;
$context['sandbox']['max'] = count($terms);
}
// Process 5 terms at a time.
$limit = 5;
$terms = array_slice($terms, $context['sandbox']['progress'], $limit);
foreach ($terms as $term) {
$converted_term = _termcase_convert_string_to_case($term->name, $case);
termcase_update_term($converted_term, $term->tid, $term->vid);
// Store some result for post-processing in the finished callback.
$context['results'][] = $term->name;
// Update our progress information.
$context['sandbox']['progress']++;
$context['sandbox']['current_term'] = $term->tid;
$context['message'] = t('Now processing %term', [
'%term' => $term->name,
]);
}
// Inform the batch engine that we are not finished,
// and provide an estimation of the completion level we reached.
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}
}