You are here

function slickgrid_callback_undo in Slickgrid 6

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

Callback function - log an message

File

./slickgrid.callbacks.inc, line 215

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 ($_POST['updated'] 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_callback_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);
    }
  }
  return array(
    'updated' => $updated_nodes,
    'field_name' => $field_name,
    'field_id' => $field_id,
  );
}