You are here

public function PhotosEditController::access in Album Photos 8.4

Same name and namespace in other branches
  1. 8.5 src/Controller/PhotosEditController.php \Drupal\photos\Controller\PhotosEditController::access()
  2. 6.0.x src/Controller/PhotosEditController.php \Drupal\photos\Controller\PhotosEditController::access()

A custom access check.

Parameters

\Drupal\Core\Session\AccountInterface $account: Run access checks for this account.

1 string reference to 'PhotosEditController::access'
photos.routing.yml in ./photos.routing.yml
photos.routing.yml

File

src/Controller/PhotosEditController.php, line 127

Class

PhotosEditController
Edit images and image details.

Namespace

Drupal\photos\Controller

Code

public function access(AccountInterface $account) {

  // Check for available parameters.
  $node = $this->routeMatch
    ->getParameter('node');
  $fid = $this->routeMatch
    ->getParameter('file');
  if ($node && $fid) {
    $nid = $node
      ->id();

    // Update cover.
    if (_photos_access('editAlbum', $node)) {

      // Allowed to update album cover image.
      return AccessResult::allowed();
    }
    else {

      // Deny access.
      return AccessResult::forbidden();
    }
  }
  elseif ($fid) {

    // Check if edit or delete.
    $current_path = $this->currentPath
      ->getPath();
    $path_args = explode('/', $current_path);
    if (isset($path_args[4])) {
      if ($path_args[4] == 'edit') {
        if (_photos_access('imageEdit', $fid)) {

          // Allowed to edit image.
          return AccessResult::allowed();
        }
      }
      elseif ($path_args[4] == 'delete') {
        if (_photos_access('imageDelete', $fid)) {

          // Allowed to delete image.
          return AccessResult::allowed();
        }
      }
    }

    // Deny access.
    return AccessResult::forbidden();
  }
  else {
    return AccessResult::neutral();
  }
}