I know that to get all available permissions you can do
var_dump(array_keys(\Drupal::service('user.permissions')->getPermissions()));
which give you a list of all permissions' name.
I also know that when you create a NodeType, it refresh this list.
So what I want to do here, is to fill a table of my database with a list of all available permissions, that update when permission is add or removed.
When I create a NodeType :
function inside_entity_insert(\Drupal\Core\Entity\EntityInterface $entity) : void
{
if (get_class($entity) === 'Drupal\node\Entity\NodeType') {
$permissions = array_keys(\Drupal::service('user.permissions')->getPermissions());
foreach ($permissions as $permission) {
// somestuff -> updating database permission table
}
}
}
So that means when NodeType is created the Drupal permissions list is updated and I must update my database too.
What I want to do here is the same thing but when a NodeType is deleted.
I tried :
- hook_entity_delete
- hook_entity_predelete
But in both hook the user.permission list didn't change, I still get the same permissions, and what I though is that the permissions of my actual nodetype dissapeared, because of the deletion.
I do not know where to look..
Is getting the name of the nodeType and delete matchings rules' name of the database, a good alternative ?
I also wanted where can I initialize these database, because actually it's created & updated only when someone create a NodeType. But that's not urgent at the moment.
Thanks to all