Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
}
}
Comment | File | Size | Author |
---|---|---|---|
#3 | 2511040-tablefield-csv-import-data-alter-hook-3.patch | 2.51 KB | alex.skrypnyk |
Comments
Comment #1
alex.skrypnykPatch attached
Comment #2
alex.skrypnykComment #3
alex.skrypnykCorrect patch attached.
Comment #4
vitalie CreditAttribution: vitalie commentedthanks @alex.designworks, looks good. I will test it a bit more and then if all well commit it.
Comment #5
vitalie CreditAttribution: vitalie commentedhey @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?
Comment #6
alex.skrypnykComment #7
jenlamptonComment #8
lolandese CreditAttribution: lolandese at HCL Technologies Limited commented