There are cases where I need to load a calendar with the default date set in the future, which can be done with PHP code, but this is expressly disallowed by the validate() method.

Patch allows PHP for default arguments, putting the risk of failure squarely on the developer.

Comments

osopolar’s picture

Does this work with insert view or with embed view?

print views_embed_view("calendar", "calendar_block_1" );

For me its not working, the view will not show. Now I'm not sure if I have an error somewhere or is it a problem which comes with the changes.

If I use the mini calendar in a block it works well, but I want to be able to use it in a node.

agentrickard’s picture

Likely an error in the PHP code you are using, especially if there are missing or different arguments.

What PHP code are you using? Or are you just using the old 'default to now' setting?

osopolar’s picture

This is the code For the date Argument:

if ('' == arg(1) || 'today' == arg(1) || !date_is_valid(arg(1), DATE_DATETIME, array('year', 'month'))) { 
  return date_format(date_now(), 'Y-m');
}
return substr(arg(1), 0, 7);

This should return YYYY-mm of the current date in the cases:
- argument is empty
- argument is today (this is my placeholder)
- or the argument is not a valid Date (year and month)

But actually I have the same Problem with:

return date_format(date_now(), 'Y-m');

The date argument is the first one. I have a second one (taxonomy term) but this I set to show all values if no argument given.

Actually its working well in as a normal block (i.e. see http://cyber4kids.de/kalender/2009-08-06). But not on my front page (http://cyber4kids.de ... should appear in the top right green box called "Kalender"; a normal page with some views inserted by insert_view; embed view will have the same problem).

To insert the view on the front page I use: [view:kalender=calendar_block_1]. If I use the default argument handling (Provide default argument -- Current date) it works fine.

Maybe I have to change something else in the calendar module.

agentrickard’s picture

If I recall correctly the date format must match that used by your argument. So if you are using month granularity 'y-m' is correct.

Also make sure that arg(1) works in this context. I don't believe that it does. And even so, it cannot always be used in a write-context.

Are you logging any errors?

osopolar’s picture

Yes I'm using month granularity (its about the mini calendar). Why do you think arg(1) won't work. I thought that maybe arg() was not working before but now its doing well ... I'll check documentation for what is the better way. ... But arg() is not the cause of this problem, because also when I just use return '2009-05' (without the php tag) it's not working (can't see the embedded calendar block).

Would you be so kind and test it with your calendar? With the insert_view module or just with views_embed_view function to see if your calendar block will show up in a page?

As I said before, the from views provided block is working well. But the strange thing is if I want to use this block with module_invoke('views', 'block', 'view', 'kalender-calendar_block_1'); it won't work.

arlinsandbulte’s picture

+1 for this feature request to allow php default arguments!
This feature might solve this issue: #174881: Make calendar default to next month.

rismondo’s picture

I used a similar patch to allow for a fixed default. It works, but then the mini calendar block disappears from the page for all pages whose address is /node/nnn (it appears on the frontpage and on the administration pages, however).

Anyone else sees the same side-effect?

MichaelP’s picture

StatusFileSize
new3.17 KB

The initial patch give me an error and didn't get all the validations to allow php supplied values rather than default current date, but I got the idea, tks @agentricard.

Here's a follow on which modifies block, attachment and style elements to allow php defaults.

This is my first patch - hope it's correct and I'm doing the right thing posting it...

wilgrace’s picture

Subscribe - is this likely to make it into the next release?

momper’s picture

subscribe

momper’s picture

tested and works ...

thanks momper

momper’s picture

but there seems to be a limitation - if i use the top navigation in the page view with week, month, day in a first testing circle it stays in the future but in a second circle it switches again to the current date?

momper’s picture

i only changed the argument as an override for the "Calendar block" display - i wanted to do this for the "Calendar page" display too, but i got this know error message in the views configuration backend, that there are no standard arguments defined ...

arlinsandbulte’s picture

#12: What do you mean?????

momper’s picture

ok - bad english :)

i have the calendar block -> everything is fine -> it shows for example the october
i click on an event day in the calender block -> the correct day is shown in the calendar page
i change with the navigation in the calendar page to the display month -> i'm in month june (wrong behaviour ...)

momper’s picture

#8 there is the file calendar_plugin_display_page.inc - this has also to be patched too ...
so everything is working now :)

arlinsandbulte’s picture

Status: Needs review » Needs work

needs work then, according to #16.
Could some one make a patch that includes everything?

Thanks

mandclu’s picture

StatusFileSize
new3.45 KB

The attached patch includes the changes from #8 with an extra instance as identified in #15.

mandclu’s picture

Status: Needs work » Needs review
tryitonce’s picture

.... so, I installed the patch - no problem.
But which php code do I put where to create a mini calender in the sitebar looking one month ahead?
Thanks for any suggestions .....

drupal_was_my_past’s picture

subscribe

jg314’s picture

subscribe

kenianbei’s picture

I'd also like to see this included, particularly in 7.x branch. I have a use case where the client needs a calendar for a specific day each year (room booking for a yearly conference). I'd like to grab that day using php for the calendar view.

simon georges’s picture

In 7.x, I succeeded in having PHP-based default arguments for the Calendar View (without any patch). The only remaining problem is: when exporting the Views, the PHP code isn't exported (same symptom as in #1202248: Exported view doesn't include 'default_argument_options' attribute).

neslee canil pinto’s picture

Issue summary: View changes
Status: Needs review » Closed (outdated)

The D6 branch is no longer supported so we're closing this issue. If you think this issue still exists in D7 you can open a new one.