You are here

public function ModerationDashboardAccess::evaluate in Moderation Dashboard 8

Same name and namespace in other branches
  1. 2.0.x 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 104

Class

ModerationDashboardAccess
Provides a 'Moderation Dashboard Access' condition.

Namespace

Drupal\moderation_dashboard\Plugin\Condition

Code

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');
}