Skip to content

Instantly share code, notes, and snippets.

@ummdorian
Created March 28, 2018 14:57
Show Gist options
  • Select an option

  • Save ummdorian/02d53271a302b01ee297eaa3d1612288 to your computer and use it in GitHub Desktop.

Select an option

Save ummdorian/02d53271a302b01ee297eaa3d1612288 to your computer and use it in GitHub Desktop.

Revisions

  1. Dorian Damon created this gist Mar 28, 2018.
    24 changes: 24 additions & 0 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    <?php

    function module_query_views_events_alter(Drupal\Core\Database\Query\AlterableInterface $query){

    // If this the right query
    if(
    $query->getMetaData('view') != ''
    && $query->getMetaData('view')->getDisplay()->display['id'] == 'block_3'
    ){

    // loop over fields in SELECT
    $fields =& $query->getFields();
    foreach($fields as $fieldIndex => $field){
    // Add an expression to the query, necessary as drupal sets
    $query->addExpression('MIN('.$field['table'].'.'.$field['field'].')', $field['alias']);
    // Remove field from select
    unset($fields[$fieldIndex]);
    }

    // Set group by
    $query->groupBy('node__field_date.entity_id');

    }
    }