public function ModerationDashboardAccess::evaluate in Moderation Dashboard 2.0.x
Same name and namespace in other branches
- 8 src/Plugin/Condition/ModerationDashboardAccess.php \Drupal\moderation_dashboard\Plugin\Condition\ModerationDashboardAccess::evaluate()
Evaluates the condition and returns TRUE or FALSE accordingly.
Return value
bool TRUE if the condition has been met, FALSE otherwise.
Overrides ConditionInterface::evaluate
File
- src/
Plugin/ Condition/ ModerationDashboardAccess.php, line 109
Class
- ModerationDashboardAccess
- Provides a 'Moderation Dashboard Access' condition.
Namespace
Drupal\moderation_dashboard\Plugin\ConditionCode
public function evaluate() {
if (!$this->configuration['enable']) {
return TRUE;
}
$dashboard_owner = $this
->getContextValue('dashboard_user');
$current_user = $this
->getContextValue('current_user');
if (is_string($dashboard_owner)) {
$dashboard_owner = $this->userStorage
->load($dashboard_owner);
}
// If the given user doesn't have a dashboard, nobody can view it.
if (!$dashboard_owner
->hasPermission('use moderation dashboard')) {
return FALSE;
}
// If the current user is on their own dashboard, they can view it.
if ($current_user
->id() === $dashboard_owner
->id()) {
return TRUE;
}
// But they can only view the dashboard of others with another permission.
return $current_user
->hasPermission('view any moderation dashboard');
}