function duration_field_query_duration_string_alter in Duration Field 8.2
Same name and namespace in other branches
- 3.0.x duration_field.module \duration_field_query_duration_string_alter()
Implements hook_query_TAG_alter().
Alters database queries tagged with the 'duration_string' tag, swapping out duration string searches with values to search against timestamps stored for durations in the database.
File
- ./
duration_field.module, line 178 - Holds hooks for the Duration Field module.
Code
function duration_field_query_duration_string_alter(AlterableInterface &$query) {
$duration_fields = duration_field_get_duration_fields();
// Only do something if there are duration fields in the database.
if (!empty($duration_fields)) {
// Get any conditions on the query.
$conditions =& $query
->conditions();
// Only do something if there are any conditions.
if (is_array($conditions)) {
$duration_tables = [];
foreach ($duration_fields as $field) {
$duration_tables[$field['entity_type'] . '__' . $field['field']
->getName()] = $field['field']
->getName();
}
// Alter any queries that use Duration strings.
duration_field_alter_query_recursive($conditions, $duration_tables);
}
}
}