function node_mass_update
Same name in other branches
- 7.x modules/node/node.admin.inc \node_mass_update()
- 9 core/modules/node/node.admin.inc \node_mass_update()
- 8.9.x core/modules/node/node.admin.inc \node_mass_update()
- 10 core/modules/node/node.admin.inc \node_mass_update()
Updates all nodes in the passed-in array with the passed-in field values.
IMPORTANT NOTE: This function is intended to work when called from a form submission handler. Calling it outside of the form submission process may not work correctly.
Parameters
array $nodes: Array of node nids or nodes to update.
array $updates: Array of key/value pairs with node field names and the value to update that field to.
string $langcode: (optional) The language updates should be applied to. If none is specified all available languages are processed.
bool $load: (optional) TRUE if $nodes contains an array of node IDs to be loaded, FALSE if it contains fully loaded nodes. Defaults to FALSE.
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.
1 call to node_mass_update()
- hook_user_cancel in core/
modules/ user/ user.api.php - Act on user account cancellations.
File
-
core/
modules/ node/ node.admin.inc, line 33
Code
function node_mass_update(array $nodes, array $updates, $langcode = NULL, $load = FALSE, $revisions = FALSE) {
// We use batch processing to prevent timeout when updating a large number
// of nodes.
if (count($nodes) > 10) {
$batch_builder = (new BatchBuilder())->setFile(\Drupal::service('extension.list.module')->getPath('node') . '/node.admin.inc')
->addOperation('_node_mass_update_batch_process', [
$nodes,
$updates,
$langcode,
$load,
$revisions,
])
->setFinishCallback('_node_mass_update_batch_finished')
->setTitle(t('Processing'))
->setErrorMessage(t('The update has encountered an error.'))
->setProgressMessage('');
batch_set($batch_builder->toArray());
}
else {
$storage = \Drupal::entityTypeManager()->getStorage('node');
if ($load && !$revisions) {
$nodes = $storage->loadMultiple($nodes);
}
foreach ($nodes as $node) {
if ($load && $revisions) {
$node = $storage->loadRevision($node);
}
_node_mass_update_helper($node, $updates, $langcode);
}
\Drupal::messenger()->addStatus(t('The update has been performed.'));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.