Skip to content

Instantly share code, notes, and snippets.

@fcjurado
Created October 9, 2018 11:44
Show Gist options
  • Save fcjurado/61e507ad941cee86a9fbf55e32673079 to your computer and use it in GitHub Desktop.
Save fcjurado/61e507ad941cee86a9fbf55e32673079 to your computer and use it in GitHub Desktop.
Drupal 8: Preprocess hook to avoid duplicates
/*
* Implements hook_preprocess_HOOK().
*/
function rest_views_views_pre_render(&$view) {
if ($view->storage->id() == 'articles') {
$matchedGroupIds = array();
foreach ($view->result as $row) {
$id = $row->_entity->id();
if(!in_array($id, $matchedGroupIds)){
array_push($matchedGroupIds, $id);
$rows[] = $row;
}
}
$view->result = $rows;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment