1 taxonomy.install | taxonomy_update_1009() |
Add new "create terms" permission to editor and admin roles.
Related topics
File
- core/
modules/ taxonomy/ taxonomy.install, line 378 - Install, update and uninstall functions for the taxonomy module.
Code
function taxonomy_update_1009() {
$config_vocab_names = config_get_names_with_prefix('taxonomy.vocabulary.');
$new_permissions = array();
foreach ($config_vocab_names as $config_vocab_name) {
$vocab = str_replace('taxonomy.vocabulary.', '', $config_vocab_name);
$new_permissions[] = "create terms in $vocab";
}
$admin_role = config_get('system.core', 'user_admin_role');
foreach (array($admin_role, 'editor') as $role_name) {
$config = config('user.role.' . $role_name);
$permissions = $config->get('permissions');
if ($permissions) {
// Permissions for each taxonomy.
foreach ($new_permissions as $new_permission) {
if (!in_array($new_permission, $permissions)) {
$permissions[] = $new_permission;
}
}
// Save the role.
$config->set('permissions', $permissions);
$config->save();
}
}
}