Granting per-node-type permissions in hook_node_type_insert() I use the Override Node Options module to specify granular permissions for publishing, leaving Revision log entries, etc. for each node type.

I almost always grant the same set of permissions to a certain role for every node type, so I thought I'd have Drupal automatically assign them on node type creation:

function MYMODULE_node_type_insert($info) {
    if(module_exists('override_node_options')) {
        user_role_grant_permissions(4, array(
            'override ' . $info-&gt;type . ' published option',
            'enter ' . $info-&gt;type . ' revision log entry'
        ));
        $role = user_role_load(4);
        drupal_set_message(t('The @role role has been given permission to publish, unpublish, and enter revision logs on @nodetype nodes.', array('@role' =&gt; $role-&gt;name, '@nodetype' =&gt; $info-&gt;type)));
    }
}


But when I do so, I get errors:


  Notice: Undefined index: override NODETYPE published option in user_role_grant_permissions() (line 3152 of /htdocs/modules/user/user.module).
  
  PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'module' cannot be null: UPDATE {role_permission} SET module=:db_update_placeholder_0 WHERE ( (rid = :db_condition_placeholder_0) AND (permission = :db_condition_placeholder_1) ); Array ( [:db_update_placeholder_0] => [:db_condition_placeholder_0] => 4 [:db_condition_placeholder_1] => override NODETYPE published option ) in user_role_grant_permissions() (line 3154 of /htdocs/modules/user/user.module).


As it happens, node_type_get_types() ( which is called by node_permissions_get_configured_types()) does not return the node type I'm in the middle of creating, even though the documentation says "This list can include types that are queued for addition or deletion."

So now I'm flummoxed. How can I set a per-node-type permission automatically when that node type is created?
So, my bet is that the new node type isn't getting added to the cached list of types that node_type_get_types() returns. At the very end of node_type_save(), it calls node_type_cache_reset(), but that's probably running too late for your code.

So try putting a call to node_type_cache_reset() at the top of your function, and hopefully that will do the trick.