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.
After installing Meta Tag Quick 7.x-2.4 I have the follwing warning when editing a Meta Tag Quick enabled content.
Warning: Invalid argument supplied for foreach() in form_type_checkboxes_value() (Zeile 2251 von /var/www/domains/less.ch/less-v4/includes/form.inc).
Comment | File | Size | Author |
---|---|---|---|
#6 | 1527006_metatags_quick.patch | 858 bytes | dDoak |
#5 | 1527006_metatags_quick.patch | 843 bytes | dDoak |
Comments
Comment #1
alicemoon CreditAttribution: alicemoon commentedI am getting a similar warning
Warning: Invalid argument supplied for foreach() in form_type_checkboxes_value() (line 2251 of ... my website path.. /includes/form.inc).
So far this seems to occur on panel pages when I first enter the path-based meta tag form - once I fill it in and save if I go back in to renter info there is no warning.
Comment #2
zerouno62 CreditAttribution: zerouno62 commentedAs I remeber the warning was showed on every page (panels, pages, articles etc.). After filling in some m eta-content the warning disappeared.
Raffaele
Comment #3
bdimaggioYeah, same issue here. I traced the problem back to just the meta_robots field (although not much further)--it goes away if you pull that field off of a content type. Note: this problem also renders nodes inoperable by Views Bulk Operations. Which is how I found out about all this.
Comment #4
aethr CreditAttribution: aethr commentedThis appears to be caused by metatags_quick_checkboxes widget which is used for the robots field. In the Drupal Forms API the '#default_value' for a 'checkboxes' form element must be an array of the "checked" options.
In the function metatags_quick_field_widget_form it appears to be trying to assign a default value for the checkboxes field based on the "default_value" of the instance. However, on a clean install the instance has no "default_value" set, which results in the checkbox form element getting a default value of NULL.
However, when the Form API attempts to process this element, it expects an array. When '#default_value' is set to NULL (instead of an empty array) it results in the "invalid foreach" error message which is being reported by the users above.
Without knowing much about this module, I'm hesitant to provide a patch. However I'd say that a simple fix would be pre-populating the "default value" for this field at creation with an empty array. Alternatively a check could be placed in metatags_quick_field_widget_form such that if a NULL value is detected in the '#default_value' of a checkbox element, it is re-initialised to an empty array.
A simple fix in the meantime is to open the Manage Fields admin page for each content type with the (Meta)Robots field attached, and click "edit field" for (Meta)Robots. At the bottom of the Edit Fields page, simply hit the Save settings button. This will populate a properly formatted default value for the field and the error will go away for that content type.
This step must be repeated for all content types that use the (Meta)Robots field.
Comment #5
dDoak CreditAttribution: dDoak commentedHere is a patch that fix this error.
Comment #6
dDoak CreditAttribution: dDoak commentedI've accidently removed usefull lines.
Sorry about that.
Comment #7
valthebaldI think Drupal fills values with empty strings, not zeros.
Shouln't
array_fill_keys($default_checkboxes, '');
fit better?
Comment #8
kingfisher64 CreditAttribution: kingfisher64 commentedThis is still popping up in 7.x-2.5. Is there a preferred patch solution given comments in #6, #7.
Warning: Invalid argument supplied for foreach() in form_type_checkboxes_value() (line 2284 of /home/sitename/public_html/includes/form.inc).
Comment #9
kingfisher64 CreditAttribution: kingfisher64 commentedProbably worth mentioning i've tried the latest dev version as well. Despite running update.php and applying the update it's still there. Cleared caches and run cron as well.
Could you just confirm valthebald that #6 is good to use for now, for myself and others finding this issue.
Many thanks.
Comment #10
valthebald#9: yes, patch from #6 is perfectly usable. I just wanted it to be slightly better to commit
Comment #11
kingfisher64 CreditAttribution: kingfisher64 commentedSuper. Applied patch in #6 as a temp fix. No more
Warning: Invalid argument supplied for foreach() in form_type_checkboxes_value() (line 2284 of /home/sitename/public_html/includes/form.inc).
If you're not happy with the patch could you apply a more satisfactory one to dev version valthebald ?
Comment #12
valthebaldFixed in 7.x-2.x-dev