I'd like to abstract out a basic date argument class. I've created one that adds an option to the default arguments to set a missing date argument to default to the current date, and I've set the existing date arguments up to use it.

I have other ideas for a date argument handler, but this seems like a good place to start.

You should make sure I've done this right, but it seems to work correctly -- it adds a where clause to the query for the current date if the argument default is set to 'Current date' and the argument is missing, and otherwise behaves normally.

CommentFileSizeAuthor
views.patch5.09 KBkarens

Comments

merlinofchaos’s picture

Default arguments are supposed to be plugins; then you can use that on any argument (tho admittedly it might not be all that useful on other types of arguments).

I'm still thinking about whether or not this is the right way to go about it. It does work, though. I need to think about it -- mostly I'm uncertain because other defaults are plugins, and this one is not.

This does make me realize that the various arguments I have for dates could be generalized. Possibly even into the same class, with a selector for the incoming date format. Then it would be very easy to have any date use it, and not just post date.

karens’s picture

That's why I did it the way I did, it didn't seem to make sense to offer a 'Current date' default on arguments that aren't dates. But this method also makes some assumptions about what format it will use for the date it creates, which is limiting.

I'm playing with another idea in the Calendar module. There I do use the plugin. It shows up on all arguments as an option, but it provides a select list of how you want the current date formatted (so that it's applicable to any date argument) and it provides a description of what it does so it won't seem so odd on arguments that aren't dates. I have it in the Calendar modules now, but I could post it here as an alternative Views patch.

karens’s picture

And I'm working on a general date argument that would apply to all dates (along with a general date filter that would apply to all dates). I've got some code for that in the Date module and just want to do some more tweaking before I post it.

merlinofchaos’s picture

Committed, though I think we definitely need to take this another step or two.

merlinofchaos’s picture

Status: Needs review » Fixed

Committed!

Anonymous’s picture

Status: Fixed » Closed (fixed)

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