I'm getting;

* warning: Invalid argument supplied for foreach() in /home/forest/public_html/modules/calendar/theme/theme.inc on line 425.
* warning: Invalid argument supplied for foreach() in /home/forest/public_html/modules/calendar/theme/calendar-week.tpl.php on line 49.

when accessing a weekly view - http://theforest.org.uk/events/2009-W31

or a daily view - http://theforest.org.uk/events/2009-08-22

though the monthly calendar seems to be working fine.

Any thoughts or suggestions? Thanks!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mxmilkiib’s picture

Title: Invalid argument supplied for foreach() ...theme.inc on line 425, calendar-week.tpl.php on line 49. » Invalid argument supplied for foreach() ... etc
mxmilkiib’s picture

looking at this again;

i don't know if it's any help, but i've noticed that the date title plus 'Prev' and 'Next' links are not there.

also, on the day view, the Items column is showing twice.

does 2.x-dev use the same db schema as 2.2? if so i could try moving back to that to see if there's any difference.

arlinsandbulte’s picture

Status: Active » Postponed (maintainer needs more info)

Did you run update.php?
Have your tried the latest module versions?

mxmilkiib’s picture

yup, update.php is always run when upgrading.

have been using the latest dev calendar and i've just upped to 6.14 and the latest dev version of date, no change in the issue. as above, the Prev and Next links are missing on all calendar views.

'Events' is a panel page, but the calendar page view with all the same symptoms can be seen @ http://theforest.org.uk/eventcalendar

i attach an image with the Default, Calendar page and Month view in case any of these might shed some light on the issue..

mxmilkiib’s picture

Status: Postponed (maintainer needs more info) » Active
FileSize
72.76 KB
marcvangend’s picture

I had the same errors since I updated to Calendar 6.x-2.2. A closer look revealed that function template_preprocess_calendar_week() was called twice: once for the Week view attachment, once for Calendar page. The second call caused the error, because the view style was still set to 'calendar' which is not a valid option for the Calendar page. Settings the Calendar page's view style to 'Calendar navigation' fixed the issue for me. Milkmiruku, your screenshots look as if your situation is identical.

mxmilkiib’s picture

fantastic, thanks! this fixed the calendar page - http://theforest.org.uk/eventcalendar - and the calendar block also.

problem being that now the calendar view has broken - http://theforest.org.uk/events

i've not got the time to fix now but i'll post with developments for others with the same issue once i've had a crack at the settings

mxmilkiib’s picture

ah, i just needed to remove and readd the calendar view in the panel, selecting 'Calendar page' at this point (which you can't change from the settings in an existing panel view item config after it has been created, which is kinda unuser friendly, but hey)

marcvangend’s picture

Maybe it's good to mention that when you fix the problem in the way I described, you have to be careful that you ONLY change the Calendar page's view style (click override if necessary). If you would update the view's default style to Calendar navigation, that might break another display.

marvil07’s picture

Category: support » bug
Status: Active » Needs review
Issue tags: +warning
FileSize
1.8 KB
9.31 KB

I could not resolve this with the solution proposed.

This is my first time trying to modify this module, so sorry if I'm not resolving this in the right way.

But here is a little patch 0001-avoid-use-unintialized-data.patch, that mainly validate data before use it; the other lines are only indentation stuff, so if you want to see only the real line changes see realminorchange.patch

StephenRobinson’s picture

Thanks, this has been driving me me nuts all day, calendar-day.tpl.php was being called twice, once with empty data, throwing 2 foreach errors.

* warning: Invalid argument supplied for foreach() in /home/%/sites/all/modules/calendar/theme/theme.inc on line 296.

* warning: Invalid argument supplied for foreach() in /home/%/sites/all/modules/calendar/theme/theme.inc on line 321.

S:)

bjordan’s picture

Comment #6 by marcvangend helped fix my issue, make sure to use the Calendar Navigation style for the Page view

renenee’s picture

I have the same exact issue mentioned in the initial post; however, I looked into Comment #6, and my views were setup already the way described in 6.x-2.2 (view style "calendar navigation" for my block view and view style "calendar" for my week view attachment). Is anyone else encountering this? Has anyone else found a solution?

alexkb’s picture

Just to add, if it's not clear, solution proposed in comment #6 will solve the issue in comment #11. Thanks!

jim.phelan’s picture

#14, rmd-14, I had the same problem, although, like you, my Calendar Pages style was set to 'calendar navigation'. I had added an additional custom attachment which had its style set to 'Calendar' - just like Day, Week, Month. However the data it contained was from a different content type (created by 'Date Wizard'). When I changed the style for this new attachment to 'Unformatted' the error went away.

haggins’s picture

Status: Needs review » Active
Issue tags: +week-view

I'm getting warning: "Invalid argument supplied for foreach() in /mypath/sites/all/modules/calendar/theme/theme.inc on line 425.", too. It only appears on week-view for the first 9 weeks of the year.

How to reproduce:
1. Use latest version of date, calendar, views 2.x
2. Set first day of week to 'monday'
3. Enable "Use ISO-8601 week numbers" (no error with this function disabled!)
4. display one of the first nine weeks "calendar/2010-W[01-09]"

I figured out that the $vars parameter of template_preprocess_calender_week() contains wrong formatted rows. Look at the following example when visiting week 01:

dpr($vars['rows']) prints:

Array
(
    [0] => Array
        (
            ...
        )

    [01] => Array
        (
            ...
        )

)

Second key should be named "1". If you visit week 08, second key is named "08". However it should always be named "1".

Does anyone else experience this bug, too?

I also tried to figure out where $vars is created - without success. Result of calendar_build_week() seems to be alright.

Since many people will have problems at the beginning of 2011 I will mark this issue as critical.

haggins’s picture

Priority: Normal » Critical
marvil07’s picture

Priority: Critical » Normal
Status: Active » Needs review

Moving to normal as it not seems like a general problem(mainly something related with specific data, see priority).
Moving to the rigth status again.

hs@henrikstrindberg.se’s picture

It's the one digit weeks 1-9 any year and only in week-view . Yes I have the save problem.

seanB’s picture

We have the same problem as #16. Week number 1 - 9 of every year gives errors:
Invalid argument supplied for foreach() in /calendar/theme/theme.inc on line 425

The template function template_preprocess_calendar_week() is only called once, so this is not the same problem as marcvangend had in #6. In about 4 weeks we are in week 1 already, so this problem is about to become pretty critical to me as well..

KoCo’s picture

+1
Same problem as #16 describes. When I switch it all off, week links need two digits.
Week links should be investigated again =(.

haggins’s picture

Status: Needs review » Active

We should mark this as "active" since there is nothing to review.

seanB’s picture

Just found out what the problem is!
- In line 404 of calendar/theme/theme.inc there is a call to template_preprocess_calendar($vars);
- It uses calendar_build_calendar() to build the $rows var
- In calendar_build_week() of includes/calendar.inc there's a call to date_week() of the dateapi on line 87. This is to get the week number based on the current date.
- The date_week function returns the week number, but for weeks 1 - 9, the week number is returned as 01, 02, 03 etc. wich results in the variable being treated as a string
- In the array_merge on line 52 of includes/calendar.inc this causes the array not to be renumbered.

The proper way to fix this I guess is to make sure the date_week() function of the Date API returns integers. If you change line 86 of includes/calendar.inc to the following this will work too:
$week = intval(date_week($curday_date));

haggins’s picture

Status: Active » Needs review
FileSize
640 bytes

Great! This fixed the issue for me. Thanks, sweetBricks!
Here it is as patchfile:

marcvangend’s picture

Good catch, sweetBricks.
This is micro-optimization, not tested, but I think we can just cast to int instead of using the intval() function which has slightly more overhead on the php level: $week = (int)date_week($curday_date);.

clintthayer’s picture

Subscribe

crutch’s picture

#24 fixed for me, subscribe

dhendriks’s picture

#24 fixed it for me as well. subscribing...

KarenS’s picture

Status: Needs review » Fixed

Good detective work, but a better fix is to fix the date_week() function, which should be returning an integer, to ensure that anything else that expects a numeric week gets one.

Thanks!

Status: Fixed » Closed (fixed)
Issue tags: -warning, -week-view

Automatically closed -- issue fixed for 2 weeks with no activity.