function social_profile_profile_access in Open Social 10.1.x
Same name and namespace in other branches
- 10.3.x modules/social_features/social_profile/social_profile.module \social_profile_profile_access()
- 10.2.x modules/social_features/social_profile/social_profile.module \social_profile_profile_access()
Implements hook_ENTITY_TYPE_access().
File
- modules/
social_features/ social_profile/ social_profile.module, line 855 - The Social profile module.
Code
function social_profile_profile_access(EntityInterface $entity, $operation, AccountInterface $account) {
$display_profile_teaser = FALSE;
$route_match = \Drupal::service('current_route_match');
$allowed_node_types = [
'landing_page',
'dashboard',
];
if ($route_match
->getRouteName() === 'entity.node.canonical') {
$node = $route_match
->getParameter('node');
if (!is_null($node) && !$node instanceof Node) {
$node = Node::load($node);
}
if ($node instanceof Node && in_array($node
->getType(), $allowed_node_types)) {
$display_profile_teaser = TRUE;
}
}
// Provides access only to viewing user profile info, like referenced data in
// featured items for landing & dashboard pages, if the current user has no
// permissions.
if ($operation === 'view' && $display_profile_teaser && !$account
->hasPermission('view any profile profile')) {
return AccessResult::allowed();
}
}