function _node_mass_update_batch_process
Same name in other branches
- 7.x modules/node/node.admin.inc \_node_mass_update_batch_process()
- 9 core/modules/node/node.admin.inc \_node_mass_update_batch_process()
- 10 core/modules/node/node.admin.inc \_node_mass_update_batch_process()
- 11.x core/modules/node/node.admin.inc \_node_mass_update_batch_process()
Implements callback_batch_operation().
Executes a batch operation for node_mass_update().
Parameters
array $nodes: An array of node IDs.
array $updates: Associative array of updates.
string $langcode: The language updates should be applied to. If none is specified all available languages are processed.
bool $load: TRUE if $nodes contains an array of node IDs to be loaded, FALSE if it contains fully loaded nodes.
bool $revisions: (optional) TRUE if $nodes contains an array of revision IDs instead of node IDs. Defaults to FALSE; will be ignored if $load is FALSE.
array|\ArrayAccess $context: An array of contextual key/values.
1 string reference to '_node_mass_update_batch_process'
- node_mass_update in core/
modules/ node/ node.admin.inc - Updates all nodes in the passed-in array with the passed-in field values.
File
-
core/
modules/ node/ node.admin.inc, line 118
Code
function _node_mass_update_batch_process(array $nodes, array $updates, $langcode, $load, $revisions, &$context) {
if (!isset($context['sandbox']['progress'])) {
$context['sandbox']['progress'] = 0;
$context['sandbox']['max'] = count($nodes);
$context['sandbox']['nodes'] = $nodes;
}
// Process nodes by groups of 5.
$storage = \Drupal::entityTypeManager()->getStorage('node');
$count = min(5, count($context['sandbox']['nodes']));
for ($i = 1; $i <= $count; $i++) {
// For each nid, load the node, reset the values, and save it.
$node = array_shift($context['sandbox']['nodes']);
if ($load) {
$node = $revisions ? $storage->loadRevision($node) : $storage->load($node);
}
$node = _node_mass_update_helper($node, $updates, $langcode);
// Store result for post-processing in the finished callback.
$context['results'][] = Link::fromTextAndUrl($node->label(), $node->toUrl())
->toString();
// Update our progress information.
$context['sandbox']['progress']++;
}
// 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'];
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.