You are here

public function AgreementHandler::agree in Agreement 8.2

Same name and namespace in other branches
  1. 3.0.x src/AgreementHandler.php \Drupal\agreement\AgreementHandler::agree()

Accept the agreement for an user account.

Parameters

\Drupal\agreement\Entity\Agreement $agreement: The agreement that the user is agreeing to.

\Drupal\Core\Session\AccountProxyInterface $account: The user account to agree.

int $agreed: An optional integer to set the agreement status to. Defaults to 1.

Return value

bool|\Symfony\Component\HttpFoundation\Cookie TRUE if the operation was successful and the user is authenticated, a cookie if the operation was successful and the user is anonymous, otherwise FALSE.

Overrides AgreementHandlerInterface::agree

File

src/AgreementHandler.php, line 87

Class

AgreementHandler
Agreement handler provides methods for looking up agreements.

Namespace

Drupal\agreement

Code

public function agree(Agreement $agreement, AccountProxyInterface $account, $agreed = 1) {
  if ($this
    ->isAnonymousAgreement($agreement, $account)) {
    return $this
      ->agreeAnonymously($account, $agreement, $agreed);
  }
  return $this
    ->agreeWhileLoggedIn($account, $agreement, $agreed);
}