Get all available permission after NodeType delete - Drupal 8 I know that to get all available permissions you can do 

var_dump(array_keys(\Drupal::service('user.permissions')-&gt;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')-&gt;getPermissions());

        foreach ($permissions as $permission) {
        // somestuff -&gt; 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 &amp; updated only when someone create a NodeType. But that's not urgent at the moment.

Thanks to all
You are using the wrong hooks. I am not sure what your objective is, but you want hook_ENTITY_BUNDLE_delete I believe:

https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21entity.api.php/function/hook_entity_bundle_delete/8.6.x

function mymodule_entity_bundle_delete($entity_type_id, $entity) : void
{
    if ($entity_type_id == 'node' &amp;&amp; $bundle == 'node type to check') {
        $permissions = array_keys(\Drupal::service('user.permissions')-&gt;getPermissions());

        foreach ($permissions as $permission) {
        // somestuff -&gt; updating database permission table
        }
     }
}


I don't know if you care to check $bundle or not, but if you delete any node type, this code should fire.