Created
February 27, 2018 16:39
-
-
Save ummdorian/5a8007e16c37e8e73aa7232550c35bae to your computer and use it in GitHub Desktop.
Views Nested Condition Group
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function adw_calendar_query_views_events_list_alter(Drupal\Core\Database\Query\AlterableInterface $query){ | |
if( | |
$query->getMetaData('view')->getDisplay()->display['id'] == 'page_1' | |
|| $query->getMetaData('view')->getDisplay()->display['id'] == 'page_2' | |
){ | |
// Get the filters set for the date range | |
$dateFilter = $query->getMetaData('view')->exposed_data['date']; | |
$startFilterFormatted = date('Y-m-d',strtotime($dateFilter['min'])); | |
$endFilterFormatted = date('Y-m-d',strtotime($dateFilter['max'])); | |
// Get the second condition which is the one we're interested in. | |
$conditions =& $query->conditions()[0]['field']->conditions()[1]['field']; | |
// Create a new conditions group | |
$newConditionGroup = $query->andConditionGroup() | |
->condition('node__field_event_start_date.field_event_start_date_value', $startFilterFormatted, '<') | |
->condition('node__field_event_end_date.field_event_end_date_value', $endFilterFormatted, '>') | |
; | |
// Add our new condition group to the second condition | |
$conditions->condition($newConditionGroup); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment