You are here

protected function AgreementForm::processAgreement in Agreement 3.0.x

Same name and namespace in other branches
  1. 8.2 src/Form/AgreementForm.php \Drupal\agreement\Form\AgreementForm::processAgreement()

Process and generate a response for successful agreements.

Parameters

\Drupal\agreement\Entity\Agreement $agreement: The agreement being processed.

int $agree: An integer to set the agreement status to.

array $storage: The form's set of arbitrary data.

string $destination: The destination to send the user to upon successful agreement.

Return value

bool|\Drupal\Core\Routing\LocalRedirectResponse A local redirect response if the agreement was processed successfully, otherwise FALSE.

1 call to AgreementForm::processAgreement()
AgreementForm::submitForm in src/Form/AgreementForm.php
Form submission handler.

File

src/Form/AgreementForm.php, line 241

Class

AgreementForm
Agreement page form.

Namespace

Drupal\agreement\Form

Code

protected function processAgreement(Agreement $agreement, int $agree, array $storage, string $destination) {
  $successfulResponse = new LocalRedirectResponse($destination);
  if ($this->agreementHandler
    ->isAnonymousAgreement($agreement, $this->account)) {
    $cookie = $this->agreementHandler
      ->agree($agreement, $this->account, $agree);
    if (!$cookie) {
      return FALSE;
    }
    $successfulResponse->headers
      ->setCookie($cookie);
    $successfulResponse
      ->addCacheableDependency((new CacheableMetadata())
      ->addCacheContexts([
      'cookies:' . $cookie
        ->getName(),
    ]));
    return $successfulResponse;
  }
  elseif ($this->agreementHandler
    ->agree($agreement, $this->account, $agree)) {
    return $successfulResponse;
  }
  return FALSE;
}