public function DrupalRolesConsumer::createConsumerTarget in Authorization 8
Create authorization consumer targets.
Parameters
string $mapping: What grant to create.
Overrides ConsumerInterface::createConsumerTarget
File
- authorization_drupal_roles/
src/ Plugin/ authorization/ Consumer/ DrupalRolesConsumer.php, line 159
Class
- DrupalRolesConsumer
- Provides a consumer for Drupal roles.
Namespace
Drupal\authorization_drupal_roles\Plugin\authorization\ConsumerCode
public function createConsumerTarget(string $mapping) : void {
$sanitizedId = $this
->sanitizeRoleId($mapping);
$storage = $this->entityTypeManager
->getStorage('user_role');
if (!$storage
->load($sanitizedId)) {
$role = $storage
->create([
'id' => $sanitizedId,
'label' => $mapping,
]);
$role
->save();
}
}