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->type . ' published option',
'enter ' . $info->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' => $role->name, '@nodetype' => $info->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?