This error/warning seems to come when you don't have encoded a default value for the field.
Here is a patch

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DuneBL created an issue. See original summary.

vitalie’s picture

Status: Active » Needs review

merci DuneBL, good catch. I had to stop mid-way through the creation of a new tablefield in order to replicate this.

In any case, I did a bit of code refactor. Please review patch in https://www.drupal.org/node/2493563#comment-10936881, comment #9 of #2493563: Default value are missing when using tablefield in an embedded form via #ajax. That patch deleted the line involved here, but at the same time, your patch is kind of contained in line 525 of the new code resulting after applying refactoring patch. If you like, could you test it? You'll have to apply it against latest dev version though.

DuneBL’s picture

I have added the patch #9 (from https://www.drupal.org/node/2493563#comment-10936881) but I still get a warning when I add a node with and empty table (and without default value defined for the tablefield).
This is not so easy to test as the warning appears only when this newly created node is saved the first time.

Warning : Invalid argument supplied for foreach() dans tablefield_field_formatter_view() (ligne 406 dans .../sites/all/modules/tablefield/tablefield.module).

Here is a small patch to handle this. As a side note, there is no need to test isset($tabledata)) and !empty($tabledata); testing only !empty($tabledata) is enough.

vitalie’s picture

Hmm, cannot reproduce. If the table is empty, then it should not get to line 406, as $items is an empty array and it never enters the foreach.

vitalie’s picture

Status: Needs review » Postponed (maintainer needs more info)
lolandese’s picture

Version: 7.x-2.4 » 7.x-2.x-dev
Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)