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.
Hi,
when creating a 'Views Flipped Table', I'm getting the following warning on every page with this table:
Warning: Invalid argument supplied for foreach() in include() (line 39 of /var/www/drupal/sites/all/modules/views_hacks/views_flipped_table/views-flipped-table.tpl.php).
The table seems to be rendered properly.
Line 39 in views-flipped-table.tpl.php
is the statement <?php foreach($row['title'] as $title): ?>
from this construct:
<?php if ($first):?>
<thead>
<tr class="<? echo $element; ?>">
<th>
</th>
<?php foreach($row['title'] as $title): ?>
<th>
<?php echo $title; ?>
</th>
<?php endforeach; ?>
</tr>
</thead>
I have no idea what seems to be the problem here.
Greetings, -asb
Comment | File | Size | Author |
---|---|---|---|
#1 | views_flipped_table-6.x-1.0-beta1-fix_foreach_error_by_checking_if_array_first.patch | 527 bytes | marc.groth |
Comments
Comment #1
marc.groth CreditAttribution: marc.groth commentedHi there,
I am also getting this error and it seems that it's because there is no title set for the table... I have attached a patch to fix this (by adding an if statement to make sure that $row['title'] is an array before doing a foreach() on it - which is what the error is complaining about). The patch will need to be applied to the correct folder (i.e. views_flipped_table root folder). The change is basically:
becomes
Is this intentional behaviour (i.e. the table has to have a title) or can this patch be applied? A check should probably be made to make sure something is an array before performing a foreach() on it, which will make sure this error isn't seen if the user decides not to give the table a title.
Many thanks,
Marc
Comment #2
infojunkie CreditAttribution: infojunkie commentedI fixed this using a different approach, by avoiding the title row altogether if no title field is present. Please try it 12 hours from now and let me know if it works as you expect.
Comment #3
infojunkie CreditAttribution: infojunkie commentedFixed in dev of course.
Comment #4
marc.groth CreditAttribution: marc.groth commentedThanks for such a quick response infojunkie.
Do you have any idea if/when this will be rolled out into beta1? Or is it just worth using dev for now instead?
Thanks again,
Marc
Comment #5
infojunkie CreditAttribution: infojunkie commentednot sure when I'll release beta2. But dev contains no major changes compared to beta1, just bug fixes, so I think you'd be safe using it.
Comment #6
asb CreditAttribution: asb commentedJust upgraded to views_hacks 6.x-1.x-dev and can confirm that the error no longer appears.
Thank you!
Comment #7
marc.groth CreditAttribution: marc.groth commentedThanks for the fix and information, infojunkie
Comment #9
naught101 CreditAttribution: naught101 commented