You are here

public function StateChangeWithRightsCheck::checkUserHasExistingRights in Commerce License 8.2

Checks whether the user already has the rights this license grants.

This is called on a configured plugin.

Parameters

\Drupal\user\UserInterface $user: The user being checked.

Return value

\Drupal\commerce_license\ExistingRights\ExistingRightsResult A rights result object specifying the result and messages.

Overrides ExistingRightsFromConfigurationCheckingInterface::checkUserHasExistingRights

File

tests/modules/commerce_license_test/src/Plugin/Commerce/LicenseType/StateChangeWithRightsCheck.php, line 39

Class

StateChangeWithRightsCheck
Reports whether it has been granted and has a rights check.

Namespace

Drupal\commerce_license_test\Plugin\Commerce\LicenseType

Code

public function checkUserHasExistingRights(UserInterface $user) {
  $state = \Drupal::state();
  $license_status = $state
    ->get('commerce_license_state_change_test');

  // If the license has been granted, report that the user has existing
  // rights.
  // This assumes that there is only one user involved in the test!
  return ExistingRightsResult::rightsExistIf($license_status == 'grantLicense', $this
    ->t("You already have the rights."), $this
    ->t("The user already has the rights."));
}