Skip to content

Instantly share code, notes, and snippets.

@luksak
Last active September 21, 2018 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luksak/0907196a41315b5876f9d630a554f41c to your computer and use it in GitHub Desktop.
Save luksak/0907196a41315b5876f9d630a554f41c to your computer and use it in GitHub Desktop.
Remove duplicate views results
<?php
/*
* Implements hook_preprocess_HOOK().
*/
function hook_preprocess_views_view_unformatted__VIEW_ID(&$variables) {
$entity_ids = [];
foreach ($variables['rows'] as $key => $row) {
$entity = $row['content']['#row']->_entity;
$id = $entity->id();
if (!in_array($id, $entity_ids)) {
$entity_ids[] = $id;
}
else {
unset($variables['rows'][$key]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment