Something is baffling me. I have this view of streams to users. An admin may make a stream to themselves, a specific person or everyone. I also have this code in which a non-admin user may see only the streams made to everyone and that specific user, whereas an admin should be able to see all streams, including the ones made to themselves. I’ve edited my code many times, but no matter what I do, I can’t get the non-admin user to see the streams to themselves. Could you maybe take a look at it and point me in the right direction? Thanks a lot in advance :slightly_smiling_face:
function hajans_crm_views_pre_render(ViewExecutable $view) {
if (isset($view) && $view->storage->id() == 'crm' && $view->current_display == 'streams_user_tab') {
foreach ($view->result as $index => $value) {
$current_user = User::load(Drupal::currentUser()->id());
if (!$current_user->hasRole('administrator')) {
$field_to = $value->_entity->field_to->value;
if ($field_to != 'Everyone' && $field_to != 'Myself') {
if ($current_user->id() !== $value->_entity->uid->target_id) {
unset($view->result[$index]);
}
}
}
}
}
}