In the submitForm
of a form of a custom module, I have this code:
$role = Role::create(['id' => 'member', 'label' => t('Member')]); $role->grantPermission('Renew membership'); $role->save();
which, according to Kint, is supposed to work.
ksm($role);
on the next line gives me
$role DrupaluserEntityRole (23) Properties (23) protected id -> string (6) "member" protected label -> UTF-8 string (8) "Adhérent" protected weight -> integer 1 ⧉protected permissions -> array (1) 0 => string (16) "Renew membership"
But when I look at /admin/people/permissions
, I get this:
The role is properly created (Adhérent), the permission too (Renew membership), but the permission is clearly not granted to the role.
What am I doing wrong (I’m using Drupal 9.3.8)?