Can help me save the results of the drupal_add_tabledrag inside of block that would be awesome. I am trying to loop through the results inside of hook_block_save() but that isn't working.

The example that I found uses the form submit button not sure how to do something similar to this inside a block.

function tabledrag_example_simple_form_submit($form, &$form_state) {
  // Because the form elements were keyed with the item ids from the database,
  // we can simply iterate through the submitted values.
  foreach ($form_state['values']['example_items'] as $id => $item) {
    db_query(
      "UPDATE {tabledrag_example} SET weight = :weight WHERE id = :id",
      array(':weight' => $item['weight'], ':id' => $id)
    );
  }
}

Inside the hook_block_save I don't think I have access to the $form_State['values']. Please help.

Thanks,
Joe

Comments

JoeRobertsPhotography’s picture

I figured it out with some help from Devel module. I printed the $edit varaible and found the values in there so I was able to use this code inside of the MYMODULE_block_save to get the updated tabledrag variables and update the weight module with the correct weights.

function MYMODULE_block_save($delta, $edit) {
  foreach ($edit['rotation_main_items'] as $id => $item) {
    db_query(
      "UPDATE {weight_weights} SET weight = :weight WHERE entity_id = :id",
      array(':weight' => $item['weight'], ':id' => $id)
    );
  }
}