class ModerationDashboardAccess in Moderation Dashboard 2.0.x
Same name in this branch
- 2.0.x src/Access/ModerationDashboardAccess.php \Drupal\moderation_dashboard\Access\ModerationDashboardAccess
- 2.0.x src/Plugin/Condition/ModerationDashboardAccess.php \Drupal\moderation_dashboard\Plugin\Condition\ModerationDashboardAccess
Checks access for displaying the scheduler list of scheduled nodes.
Hierarchy
- class \Drupal\moderation_dashboard\Access\ModerationDashboardAccess implements AccessCheckInterface
Expanded class hierarchy of ModerationDashboardAccess
1 string reference to 'ModerationDashboardAccess'
1 service uses ModerationDashboardAccess
File
- src/
Access/ ModerationDashboardAccess.php, line 14
Namespace
Drupal\moderation_dashboard\AccessView source
class ModerationDashboardAccess 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_moderation_dashboard');
}
/**
* 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.
*
* @param \Drupal\Core\Session\AccountInterface $account
* Current account.
*/
public function access(AccountInterface $account) {
$dashboard_owner = $account;
$current_user_id = $this->routeMatch
->getParameter('user');
// If the current user is on their own dashboard, they can view it.
if ($current_user_id === $dashboard_owner
->id() && $dashboard_owner
->hasPermission('use moderation dashboard')) {
return AccessResult::allowed();
}
// If the given user doesn't have a dashboard, nobody can view it.
if (!$dashboard_owner
->hasPermission('use moderation dashboard') && !$dashboard_owner
->hasPermission('view any moderation dashboard')) {
return AccessResult::forbidden('User does not have access to view this dashboard.');
}
// But they can only view the dashboard of others with another permission.
if ($dashboard_owner
->hasPermission('view any moderation dashboard')) {
return AccessResult::allowed();
}
else {
return AccessResult::forbidden();
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ModerationDashboardAccess:: |
protected | property | The current route match. | |
ModerationDashboardAccess:: |
public | function | Determine if the $account has access to the scheduled content list. | |
ModerationDashboardAccess:: |
public | function |
Declares whether the access check applies to a specific route or not. Overrides AccessCheckInterface:: |
|
ModerationDashboardAccess:: |
public | function | Constructs a ScheduledListAccess object. |