function node_mass_update

node_mass_update(array $nodes, array $updates, $langcode = NULL, $load = FALSE, $revisions = FALSE)

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.

File

core/modules/node/node.admin.inc, line 33
Content administration and module settings user interface.

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 = array(
      'operations' => array(
        array('_node_mass_update_batch_process', array($nodes, $updates, $langcode, $load, $revisions))
      ),
      'finished' => '_node_mass_update_batch_finished',
      'title' => t('Processing'),
      // We use a single multi-pass operation, so the default
      // 'Remaining x of y operations' message will be confusing here.
      'progress_message' => '',
      'error_message' => t('The update has encountered an error.'),
      // The operations do not live in the .module file, so we need to
      // tell the batch engine which file to load before calling them.
      'file' => drupal_get_path('module', 'node') . '/node.admin.inc',
    );
    batch_set($batch);
  }
  else {
    if ($load && !$revisions) {
      $nodes = Node::loadMultiple($nodes);
    }
    foreach ($nodes as $node) {
      if ($load && $revisions) {
        $node = entity_revision_load('node', $node);
      }
      _node_mass_update_helper($node, $updates, $langcode);
    }
    drupal_set_message(t('The update has been performed.'));
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!node!node.admin.inc/function/node_mass_update/8.1.x