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.
On importing Serialized flexifilter code, I get the error message:
warning: Invalid argument supplied for foreach() in /www/public_html/sites/all/modules/flexifilter/flexifilter.module on line 550.
Here's how:
- Add new flexifilter
- Enter Label: test
- Enter Description/filter tips: Test Description
- Create (which is successful)
- Edit test
- Click export, and select the Serialized flexifilter (for manual imports):
a:9:{s:5:"label";s:4:"Test";s:11:"description";s:16:"Test Description";s:2:"id";s:1:"3";s:7:"enabled";b:1;s:8:"advanced";b:0;s:5:"delta";s:1:"1";s:5:"cache";s:1:"1";s:10:"components";a:2:{s:7:"id_next";i:32;s:9:"id_prefix";s:22:"flexifilter_component_";}s:3:"fid";s:3:"new";}
- Delete test filter
- Click Import a flexifilter
- Paste Serialized flexifilter code, and click import, produces the error:
warning: Invalid argument supplied for foreach() in /www/public_html/sites/all/modules/flexifilter/flexifilter.module on line 550.
Comments
Comment #1
bigjim CreditAttribution: bigjim commentedhad the same problem
with this simple filter
a:9:{s:5:"label";s:6:"simple";s:11:"description";s:22:"simple shortcuts";s:2:"id";s:1:"2";s:7:"enabled";b:1;s:8:"advanced";b:0;s:5:"delta";s:1:"1";s:5:"cache";s:1:"1";s:10:"components";a:4:{i:0;a:3:{s:5:"class";s:24:"flexifilter_text_replace";s:8:"settings";a:3:{s:4:"find";s:3:"d.o";s:7:"replace";s:10:"drupal.org";s:4:"step";s:7:"process";}s:2:"id";s:2:"30";}i:1;a:3:{s:5:"class";s:24:"flexifilter_text_replace";s:8:"settings";a:3:{s:4:"find";s:4:"civi";s:7:"replace";s:7:"CiviCRM";s:4:"step";s:7:"process";}s:2:"id";s:2:"31";}s:7:"id_next";i:32;s:9:"id_prefix";s:22:"flexifilter_component_";}s:3:"fid";s:3:"new";}
Comment #2
iantresman CreditAttribution: iantresman commentedI've also tried importing the corrected Link Formatting example, and the "Swear Filter" further down the page, and get the same error message.
Perhaps it is also worth mentioning that the page on which this error is displayed is:
admin/build/flexifilters/a/edit
...and also shows "page not found".
I'm running PHP 5.2.13 (with 48M memory limit) with mySQL 5.0.77.
Comment #3
ibaal CreditAttribution: ibaal commentedSame problem here.
The problem seems to be improper/missing unserialzation of the filter. Resulting in the foreach loop getting a string when it actually wants an array/list/whatever. I added
$filter = unserialize($filter);
as the first line offunction flexifilter_save_filter($filter)
. (the function starts at line 490). I haven't studied the code enough to have any opinion if this is the proper place to add unserialization, but it seems to work for me.Comment #4
sin CreditAttribution: sin commented#3 works for importing:
MediaWiki Extended filter http://drupal.org/sandbox/risca/1200940
Just comment it out after import.
Comment #5
madmanmax CreditAttribution: madmanmax commentedFor those who get the error message:
It appears that the serialized flexifilter you entered was improperly formed. Please check the source.
The problem is that it tries to unserialize the import string but it fails. Your most likely candidate is if you have a big chunk of string but the string count is wrong. Example if you're trying to import the MediaWiki Extended filter my count was wrong for the code part.
How to find the right count? For the sake of example we'll assume the number of chars is invalid (5 instead of 4).
s:5:"step";
var_dump
which will return the number of characters (in this case 11)If you passed this but instead get to a page not found:
Page not found The requested page could not be found.
and the link points to/admin/build/flexifilters/a/edit
.Solution: mentioned in comment 3.
Comment #6
sdsheridanActually, i think the issue is in how the function gets called on import. The unserialisation is already done in the submit function for the import form, but then the serialised string is passed to the function
flexifilter_save_filter()
instead of the already unserialised array. The change should probably be in the functionflexifilter_filter_input_form_submit()
in file flexifilter.admin.inc as follows (with better-named variables):And, if we want to get closer to Drupal coding standards, then we shouldn't be using a
drupal_goto()
call here (as that aborts any other submit handlers that may come after this one), but rather setting$form_state['redirect']
. And while we're at it, a confirmation message would be nice too:Shawn