I have pages in a view that I want to display during a season and there is a field that is a taxonomy of {summer, fall, winter, spring}. My problem is that I cannot figure out how to get the current season and compare it to the field in my pages. I can calculate the season using php:
$value = '';
$today = new DateTime();
echo 'Today is: ' . $today->format('m-d-Y') . '<br />';// get the season dates
$spring = new DateTime('March 20');
$summer = new DateTime('June 20');
$fall = new DateTime('September 22');
$winter = new DateTime('December 21');switch(true) {
case $today >= $spring && $today < $summer:
$value = 'spring';
break;case $today >= $summer && $today < $fall:
$value = 'summer';
break;case $today >= $fall && $today < $winter:
$value = 'autumn';
break;default:
$value = 'winter';!';
}
And I tried to put it into the computed_field module's field, but I can't figure out how to use it inside views. How can I access $value and require that the season field equal this value to display the page?
Comments
What actions will you do
What actions will you do after you detect a season?
actions
I want the view to display the content tagged with the current season
I think, we can accomplish
I think, we can accomplish this with a custom module.
Share the name of your view.
Also, share the name of the
Also, share the name of the field that contains season term.
answers
Thanks the the help
The view is names "pests"
The field is called "seasons"
Seasons is a list of up to 4 season strings, which are in a taxonomy called seasons, and are ctl-clicked from a dropdown list in contents of type "Pest of the month"
Thanks for the help
Here is the view:
I see that in your code you
I see that in your code you wrote:
$value = 'autumn';
What is correct term's name 'autumn' or 'fall'?
I used the 'fall' name, but if it is not correct, you can correct it itself.
autumn
I arbitrarily used autumn
I have created the solution
I have created the solution here: https://www.drupal.org/sandbox/wombatbuddy/3108024
Create the 'Has taxonomy term ID' contextual filter and install the module.
The module calculate the current season using the rules provided by client.
Then extracted term id of a term that has name which is equal to the current season.
After that the term id is passed into the view as the argument for the contextual filter.
Thanks a lot!
I downloaded the two files, put them in a module directory called views_season_argument, enabled it, and created the contextual filter as illustrated (using the defaults). But I do not see where to use your new module in the view. What is the ID to look for in the filter?
It is displaying the correct things for winter with no extra contextual filters,
You don't have to do anything
You don't have to do anything.
Wow, so easy
And thank you again. I learned a lot from your code. I have never understood before where to put the hook code.
If it’s not a secret, what
If it’s not a secret, what pests are you talking about?
try this
http://jarfx.dyndns.org/bpc/bpc/web/contact
But I am working on getting https going.