You are here

public function ScheduledListAccess::access in Scheduler 8

Determine if the $account has access to the scheduled content list.

The result will vary depending on whether the page being viewed is the user profile page or the scheduled content admin overview.

File

src/Access/ScheduledListAccess.php, line 46

Class

ScheduledListAccess
Checks access for displaying the scheduler list of scheduled nodes.

Namespace

Drupal\scheduler\Access

Code

public function access(AccountInterface $account) {

  // When viewing a user profile page routeMatch->getRawParameter('user')
  // returns the user's id. If not on a user page it returns NULL silently.
  $viewing_own_tab = $this->routeMatch
    ->getRawParameter('user') == $account
    ->id();

  // Users with 'schedule publishing of nodes' can see their own scheduled
  // content via a tab on their user page. Users with 'view scheduled content'
  // will be able to access the 'scheduled' tab for any user, and also access
  // the scheduled content overview page.
  $allowed = $account
    ->hasPermission('view scheduled content') || $viewing_own_tab && $account
    ->hasPermission('schedule publishing of nodes');
  return $allowed ? AccessResult::allowed() : AccessResult::forbidden();
}