You are here

function slickgrid_callback_undo in Slickgrid 7

Same name and namespace in other branches
  1. 6 slickgrid.callbacks.inc \slickgrid_callback_undo()

Callback function - undo (revert nodes)

File

includes/slickgrid.callbacks.inc, line 172

Code

function slickgrid_callback_undo() {
  $field_name = $_POST['field_name'];
  $field_id = $_POST['field_id'];
  $updated_nodes = $_POST['updated'];
  if (is_array($updated_nodes)) {
    foreach ($updated_nodes as $nid => $node) {
      $node_revision = node_load($nid, $node['vid']);
      $node_revision->revision = 1;
      $node_revision->log = t('Copy of the revision from %date.', array(
        '%date' => format_date($node_revision->revision_timestamp),
      ));
      node_save($node_revision);
    }

    // All nodes have been reverted - need to get the values from the view
    $view = slickgrid_get_view($_POST['view'], $_POST['display_id'], array_keys($updated_nodes));
    foreach ($view->result as $count => $row) {
      $updated_nodes[$row->nid]['value'] = $view
        ->render_field($field_id, $count);
    }
  }
  drupal_set_message(format_plural(count($updated_nodes), 'Reset changes to 1 item.', 'Reset changes to @count items.'));
  return array(
    'updated' => $updated_nodes,
    'field_name' => $field_name,
    'field_id' => $field_id,
  );
}