You are here

public function SocialAlbumController::checkViewImageAccess in Open Social 10.1.x

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_album/src/Controller/SocialAlbumController.php \Drupal\social_album\Controller\SocialAlbumController::checkViewImageAccess()
  2. 10.0.x modules/social_features/social_album/src/Controller/SocialAlbumController.php \Drupal\social_album\Controller\SocialAlbumController::checkViewImageAccess()
  3. 10.2.x modules/social_features/social_album/src/Controller/SocialAlbumController.php \Drupal\social_album\Controller\SocialAlbumController::checkViewImageAccess()

Checks access to the page for viewing the image from the post.

Parameters

\Drupal\node\NodeInterface $node: The node entity object.

\Drupal\social_post\Entity\PostInterface $post: The post entity object.

int $fid: The file entity ID.

string $operation: (optional) The operation to be performed. Defaults to view.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

1 call to SocialAlbumController::checkViewImageAccess()
SocialAlbumController::checkDeleteImageAccess in modules/social_features/social_album/src/Controller/SocialAlbumController.php
Checks access to the page for deleting the image from the post.
1 string reference to 'SocialAlbumController::checkViewImageAccess'
social_album.routing.yml in modules/social_features/social_album/social_album.routing.yml
modules/social_features/social_album/social_album.routing.yml

File

modules/social_features/social_album/src/Controller/SocialAlbumController.php, line 246

Class

SocialAlbumController
Returns responses for Album routes.

Namespace

Drupal\social_album\Controller

Code

public function checkViewImageAccess(NodeInterface $node, PostInterface $post, $fid, $operation = 'view') {
  if ($this
    ->checkAlbumAccess($node) && $post
    ->access($operation) && $post
    ->bundle() === 'photo' && !$post->field_album
    ->isEmpty() && $post->field_album->target_id === $node
    ->id() && !$post->field_post_image
    ->isEmpty()) {
    foreach ($post->field_post_image
      ->getValue() as $item) {
      if ($item['target_id'] === $fid) {
        return AccessResult::allowed();
      }
    }
  }
  return AccessResult::forbidden();
}