Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
WCMS
uw_ct_event
Commits
d21d047c
Commit
d21d047c
authored
Dec 13, 2018
by
Tyler Struyk
Browse files
ISTWCMS-2798: 404 events archives
parent
bd004521
Changes
1
Hide whitespace changes
Inline
Side-by-side
uw_ct_event.module
View file @
d21d047c
...
...
@@ -253,6 +253,58 @@ function uw_ct_event_form_alter(&$form, &$form_state, $form_id) {
}
}
/**
* Implements hook_views_post_render().
*
* Return 404 if the date argument is +/- current date and there are
* no future/past ahead/behind it.
*/
function
uw_ct_event_views_post_render
(
&
$view
,
&
$output
,
&
$cache
)
{
if
(
$view
->
name
==
'events_responsive'
&&
$view
->
current_display
==
'events_archive_page'
&&
count
(
$view
->
result
)
==
0
)
{
$first_arg
=
check_plain
(
$view
->
args
[
0
]);
if
(
isset
(
$first_arg
))
{
$one_year_future_time
=
strtotime
(
'+1 years'
);
$one_year_past_time
=
strtotime
(
'-1 years'
);
$first_arg_time
=
strtotime
(
$first_arg
);
if
(
$first_arg_time
>
strtotime
(
'+1 day'
,
$one_year_future_time
))
{
// Get the furthest in the future event date.
// If it is greater than that, then throw 404.
// Add a day so we do not have to worry about timezones.
$future_date
=
format_date
(
strtotime
(
'+1 days'
,
$first_arg_time
),
'custom'
,
'c'
);
$futureQuery
=
new
EntityFieldQuery
();
$future_results
=
$futureQuery
->
entityCondition
(
'entity_type'
,
'node'
)
->
propertyCondition
(
'status'
,
1
)
->
fieldCondition
(
'field_event_date'
,
'value2'
,
$future_date
,
'>'
)
->
execute
();
if
(
empty
(
$future_results
))
{
drupal_not_found
();
drupal_exit
();
}
}
if
(
$first_arg_time
<
strtotime
(
'-1 day'
,
$one_year_past_time
))
{
// Get the earliest previous event data.
// If it is less than that, then throw 404.
// Subtract a day so we do not have to worry about timezones.
$past_date
=
format_date
(
strtotime
(
'-1 days'
,
$first_arg_time
),
'custom'
,
'c'
);
$pastQuery
=
new
EntityFieldQuery
();
$past_results
=
$pastQuery
->
entityCondition
(
'entity_type'
,
'node'
)
->
propertyCondition
(
'status'
,
1
)
->
fieldCondition
(
'field_event_date'
,
'value'
,
$past_date
,
'<'
)
->
execute
();
if
(
empty
(
$past_results
))
{
drupal_not_found
();
drupal_exit
();
}
}
}
}
}
/**
* Implements hook_views_pre_render().
*
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment