Bug found for tablefield 7.x-2.2:

When implementing table field in an unlimited field format for a node, any programmatic call to load the existing node renders only the first tablefield child with the formatted 'tabledata' property.

This appears to be due to an issue of the hook_field_load functionality only expecting one value ($table[0]).

I haven't committed a patch to a public project before, but I believe the following resolves the issue by allowing multiple table $values with tablefield_rationalize_table() functionality, and would love some help verifying the adoption:

/**
 * Implements hook_field_load().
 */
function tablefield_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) {
  foreach ($items as $delta => $table) {
        foreach($table as $id=>$field){
                if (isset($field['value'])) {
                        $items[$delta][$id]['tabledata'] = tablefield_rationalize_table(unserialize($field['value']));
                }
        }
  }
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

I applied this "patch" and it solved a problem with multiple setting and using entity translation. I also applied the patch from https://www.drupal.org/node/2231009.

Now tablefield works for me as expected!

jenlampton’s picture

Nice work on your first fix @mark_schaal !!!

I've created a patch out of the recommended fix, along with some formatting cleanup. Here in Drupal-land we use two spaces for indentation, and we put lots of spaces in the foreaches for better legibility. Take a look at the patch file if you are curious about the cleanup.

  • jenlampton committed cff3894 on 7.x-2.x
    Issue #2193163 by mark_schaal: Clean up hook_field_load() so that...
jenlampton’s picture

Status: Needs review » Fixed

This fix will go into the next release for tablefield.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.