Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Implements hook_views_pre_render().
- */
- function MODULE_views_pre_render(ViewExecutable $view) {
- if (!empty($view->result)) {
- $entities = [
- 'your_custom_entity_id',
- 'another_entity_id',
- ];
- foreach ($view->result as $key => $result) {
- if (empty($result->_entity)) {
- continue;
- }
- if (!in_array($result->_entity->getEntityTypeId(), $entities)) {
- continue;
- }
- $access = Drupal::entityTypeManager()
- ->getAccessControlHandler($result->_entity->getEntityTypeId())
- ->access($result->_entity, 'view', NULL, TRUE);
- if (!$access->isAllowed()) {
- unset($view->result[$key]);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment