public function Role::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
- src/
Plugin/ Commerce/ LicenseType/ Role.php, line 81
Class
- Role
- Provides a license type which grants one or more roles.
Namespace
Drupal\commerce_license\Plugin\Commerce\LicenseTypeCode
public function checkUserHasExistingRights(UserInterface $user) {
$role_id = $this->configuration['license_role'];
$role = \Drupal::service('entity_type.manager')
->getStorage('user_role')
->load($role_id);
return ExistingRightsResult::rightsExistIf($user
->hasRole($role_id), $this
->t("You already have the @role-label role.", [
'@role-label' => $role
->label(),
]), $this
->t("User @user already has the @role-label role.", [
'@user' => $user
->getDisplayName(),
'@role-label' => $role
->label(),
]));
}