Guest User

Untitled

a guest
Feb 13th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. /**
  2. * Implements hook_views_pre_render().
  3. */
  4. function MODULE_views_pre_render(ViewExecutable $view) {
  5. if (!empty($view->result)) {
  6. $entities = [
  7. 'your_custom_entity_id',
  8. 'another_entity_id',
  9. ];
  10.  
  11. foreach ($view->result as $key => $result) {
  12. if (empty($result->_entity)) {
  13. continue;
  14. }
  15.  
  16. if (!in_array($result->_entity->getEntityTypeId(), $entities)) {
  17. continue;
  18. }
  19.  
  20. $access = Drupal::entityTypeManager()
  21. ->getAccessControlHandler($result->_entity->getEntityTypeId())
  22. ->access($result->_entity, 'view', NULL, TRUE);
  23.  
  24. if (!$access->isAllowed()) {
  25. unset($view->result[$key]);
  26. }
  27. }
  28. }
  29. }
Add Comment
Please, Sign In to add comment