function nodeaccess_node_type_insert in Nodeaccess 8.2
Same name and namespace in other branches
- 8 nodeaccess.module \nodeaccess_node_type_insert()
- 7 nodeaccess.module \nodeaccess_node_type_insert()
Implements hook_ENTITY_TYPE_insert().
File
- ./
nodeaccess.module, line 229 - Control access to site content based on the users and roles.
Code
function nodeaccess_node_type_insert(NodeTypeInterface $type) {
$config = \Drupal::configFactory()
->getEditable('nodeaccess.settings');
// New node type, default to whatever is set for access content permission.
$role_perms = user_role_permissions([
DRUPAL_ANONYMOUS_RID,
DRUPAL_AUTHENTICATED_RID,
]);
$anonymous_access = (int) in_array('access content', $role_perms[DRUPAL_ANONYMOUS_RID]);
$authenticated_access = (int) in_array('access content', $role_perms[DRUPAL_AUTHENTICATED_RID]);
$grants[DRUPAL_ANONYMOUS_RID] = [
'grant_view' => $anonymous_access,
'grant_update' => 0,
'grant_delete' => 0,
];
$grants[DRUPAL_AUTHENTICATED_RID] = [
'grant_view' => $authenticated_access,
'grant_update' => 0,
'grant_delete' => 0,
];
$grants['author'] = [
'grant_view' => 0,
'grant_update' => 0,
'grant_delete' => 0,
];
$allowed_types = $config
->get('allowed_types');
$allowed_types[$type
->id()] = 0;
$config
->set($type
->id(), $grants)
->set('allowed_types', $allowed_types)
->save();
node_access_needs_rebuild(TRUE);
}