function _node_mass_update_helper

Same name and namespace in other branches
  1. 7.x modules/node/node.admin.inc \_node_mass_update_helper()
  2. 9 core/modules/node/node.admin.inc \_node_mass_update_helper()
  3. 8.9.x core/modules/node/node.admin.inc \_node_mass_update_helper()
  4. 10 core/modules/node/node.admin.inc \_node_mass_update_helper()

Updates individual nodes when fewer than 10 are queued.

Parameters

\Drupal\node\NodeInterface $node: A node to update.

array $updates: Associative array of updates.

string $langcode: (optional) The language updates should be applied to. If none is specified all available languages are processed.

Return value

\Drupal\node\NodeInterface An updated node object.

See also

node_mass_update()

2 calls to _node_mass_update_helper()
node_mass_update in core/modules/node/node.admin.inc
Updates all nodes in the passed-in array with the passed-in field values.
_node_mass_update_batch_process in core/modules/node/node.admin.inc
Implements callback_batch_operation().

File

core/modules/node/node.admin.inc, line 82

Code

function _node_mass_update_helper(NodeInterface $node, array $updates, $langcode = NULL) {
    $langcodes = isset($langcode) ? [
        $langcode,
    ] : array_keys($node->getTranslationLanguages());
    // For efficiency manually save the original node before applying any changes.
    $node->original = clone $node;
    foreach ($langcodes as $langcode) {
        foreach ($updates as $name => $value) {
            $node->getTranslation($langcode)->{$name} = $value;
        }
    }
    $node->save();
    return $node;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.