public function Role::revokeLicense in Commerce License 8.2
Reacts to the license being revoked.
The license's privileges should be removed from its user. This is called during preSave(), so values may be set on the license entity.
Parameters
\Drupal\commerce_license\Entity\LicenseInterface $license: The license entity.
Overrides LicenseTypeInterface::revokeLicense
File
- src/
Plugin/ Commerce/ LicenseType/ Role.php, line 64
Class
- Role
- Provides a license type which grants one or more roles.
Namespace
Drupal\commerce_license\Plugin\Commerce\LicenseTypeCode
public function revokeLicense(LicenseInterface $license) {
// Get the role ID that this license grants.
$role_id = $license->license_role
->first()->target_id;
// Get the owner of the license and remove that role.
$owner = $license
->getOwner();
if (!$owner
->isAnonymous()) {
$owner
->removeRole($role_id);
$owner
->save();
}
// TODO: Log this, as it's something admins should see?
}