daily pastebin goal
23%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top