Created
October 9, 2018 11:44
-
-
Save fcjurado/61e507ad941cee86a9fbf55e32673079 to your computer and use it in GitHub Desktop.
Drupal 8: Preprocess hook to avoid duplicates
This file contains 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
/* | |
* 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