After upgrading from 7.x-1.0-beta3 to 7.x-1.0-beta4, I started getting several PHP undefined index notices when displaying a View block that is set up to show the "city" from an address field. For example:
Notice: Undefined index: name_line in _addressfield_render_address() (line 223 of /sites/all/modules/addressfield/addressfield.module)
Other undefined indices include country, postal code, premise, and thoroughfare. I.e., all the keys except "city" are undefined.
In comparing the code at line 223 in addressfield.module, it looks like there used to be a critical isset() check in beta3 that was removed in beta4.
- $child['#children'] = isset($address[$key]) ? check_plain($address[$key]) : '';
+ $child['#children'] = check_plain($address[$key]);
Any reason it was removed? Can it be put back?
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | addressfield-1997572-suppress_field_warnings.patch | 1.06 KB | xurizaemon |
| #7 | addressfield-1997572-7.patch | 467 bytes | plach |
Comments
Comment #1
rszrama commentedLooking at that line in beta3, it appears to me you added that isset() yourself: http://drupalcode.org/project/addressfield.git/blob/fc024d23ffe7791127c2...
That leads me to believe there's some other customization in your site that is causing it to attempt to render an address using a format that doesn't have corresponding address elements. Whatever the issue, I can make it more defensive.
Commit: http://drupalcode.org/project/addressfield.git/commitdiff/57883f9
Comment #3
boabjohn commentedHi guys,
Not a coder, but we are getting exactly the same notices and I've definitely not touched the isset()
We are on 7.x-1.0-beta4
This started when I added a View with aggregation to get a count of nodes, summarised on country.
Happy to export the view for further inspection...here's asample of the notices (appears to be one for every addressfield component):
Comment #4
rszrama commentedNote that this was fixed after the beta4 release, hence the issue still showing for you. : )
Update to -dev and it'll be gone.
Comment #5
boabjohn commentedThanks and sorry for missing the clue!
Comment #6
Anonymous (not verified) commentedHello, I am sorry to reopen this issue but it is the exact same problem with the exact same line number and code. Tested on beta5 and dev releases.
I had to expand on the patch. I was getting errors for "administrative_area" (it seems sometimes it is set to "--") and also for "dependent_locality" (one entry was set to blank or a space or something). I'm not sure if this breaks anything, hopefully not... but at least now my reports don't show errors at the top of the page.
Comment #7
plachI'm seeing notices with the current -dev too. The attached patch gets rid of them here.
Comment #8
xurizaemonI had to add back the original isset as well. This bug may require testing with "incomplete" (or just not US-formatted) addresses, which would explain why it doesn't appear for some people? FWIW I was seeing the issue on the default Commerce Reports page.
Ryan, 57883f9 doesn't fix it because
$address[$key]is unset, and is used in line 252 (even in an isset, if it's not the subject of the isset).Comment #9
mglaman@xurizaemon's patch worked and exact use case: Commerce Reports. The Views aggregate and use addressfield for charts. I tested on Customer Profiles created using devel_generate and had notices arise.
Tested on beta5: projects[addressfield][version] = 1.0-beta5
Comment #10
millionleaves commentedXurizaemon's patch worked for me in the same use case.
Comment #12
bojanz commentedCommitted, thanks.