Provide hook_tablefield_import_csv_alter() to alter CSV file data after upload but before output to the screen for editing.

/**
 * Implements hook_tablefield_import_csv_alter().
 */
function EXAMPLE_tablefield_import_csv_alter(&$data, $field_name) {
  // Filter by tablefield field name.
  if ($field_name == 'field_example') {
     // Manipulate $data.
  }
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alex.skrypnyk’s picture

Status: Active » Needs review
FileSize
2.51 KB

Patch attached

alex.skrypnyk’s picture

alex.skrypnyk’s picture

Correct patch attached.

vitalie’s picture

thanks @alex.designworks, looks good. I will test it a bit more and then if all well commit it.

vitalie’s picture

hey @alex.designworks, what do you think about:

1. adding a tablefield.api.php file to include the example of how to use the alter hook

2. ensure the table is actually rectangular after the alter. I know that the current import function does not do it either, but since the patch introduces a way to easily change the table data, maybe that would be good to have. Tablefield expects the table array to be rectangular.

That is, the patch calculates the max col count, however it does not mean that every row necessarily has that max col count. Can you add code to ensure that?

alex.skrypnyk’s picture

Assigned: Unassigned » alex.skrypnyk
jenlampton’s picture

Status: Needs review » Needs work
lolandese’s picture

Version: 7.x-2.4 » 7.x-3.x-dev