You are here

class ScheduledListAccess in Scheduler 8

Checks access for displaying the scheduler list of scheduled nodes.

Hierarchy

Expanded class hierarchy of ScheduledListAccess

1 string reference to 'ScheduledListAccess'
scheduler.services.yml in ./scheduler.services.yml
scheduler.services.yml
1 service uses ScheduledListAccess
access_checker.scheduler_content in ./scheduler.services.yml
Drupal\scheduler\Access\ScheduledListAccess

File

src/Access/ScheduledListAccess.php, line 14

Namespace

Drupal\scheduler\Access
View source
class ScheduledListAccess implements AccessCheckInterface {

  /**
   * The current route match.
   *
   * @var \Drupal\Core\Routing\RouteMatchInterface
   */
  protected $routeMatch;

  /**
   * Constructs a ScheduledListAccess object.
   *
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The current route match.
   */
  public function __construct(RouteMatchInterface $route_match) {
    $this->routeMatch = $route_match;
  }

  /**
   * {@inheritdoc}
   */
  public function applies(Route $route) {
    return $route
      ->hasRequirement('_access_scheduler_content');
  }

  /**
   * 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.
   */
  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();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ScheduledListAccess::$routeMatch protected property The current route match.
ScheduledListAccess::access public function Determine if the $account has access to the scheduled content list.
ScheduledListAccess::applies public function Declares whether the access check applies to a specific route or not. Overrides AccessCheckInterface::applies
ScheduledListAccess::__construct public function Constructs a ScheduledListAccess object.