function NodeBulkUpdate::processNode

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|null $langcode: (optional) The language updates should be applied to. If NULL all available languages are processed.

Return value

\Drupal\node\NodeInterface An updated node object.

See also

self::process()

2 calls to NodeBulkUpdate::processNode()
NodeBulkUpdate::batchProcess in core/modules/node/src/NodeBulkUpdate.php
Executes a batch operation for processing a node bulk update.
NodeBulkUpdate::process in core/modules/node/src/NodeBulkUpdate.php
Updates all nodes in the passed-in array with the passed-in field values.

File

core/modules/node/src/NodeBulkUpdate.php, line 89

Class

NodeBulkUpdate
Provides a service to update nodes in bulk.

Namespace

Drupal\node

Code

protected static function processNode(NodeInterface $node, array $updates, string|null $langcode = NULL) : NodeInterface {
  $langcodes = isset($langcode) ? [
    $langcode,
  ] : array_keys($node->getTranslationLanguages());
  // For efficiency manually save the original node before applying any
  // changes.
  $node->setOriginal(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.