Last active
September 21, 2018 08:33
-
-
Save luksak/0907196a41315b5876f9d630a554f41c to your computer and use it in GitHub Desktop.
Remove duplicate views results
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 | |
/* | |
* 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