2

If you remove "Administer vocabularies and terms" from a role in Drupal 8.4, but you want to give access to a role for a specific Vocabulary, there is no out-of-the-box way to do this for "create" access for terms in specific vocabularies.

For example, for a Vocabulary called "Author".

You are given the option to "Delete terms from Author" and "Edit terms in Author", but no option to "Create terms in Author".

enter image description here

How would you add this option a role in Drupal 8 after you have removed the "Administer vocabularies and terms" permission?

1 Answer 1

4

You can create a custom permission: "Create new authors" in mymodule.permissions.yml:

create new authors:
  title: 'Create New Authors'
  description: 'Create New Author Taxonomy Terms'
  restrict access: true

Assign the new permission to the roles you want.

Then using hook__access_entity_create_access():

function mymodule__access_entity_create_access(\Drupal\Core\Session\AccountInterface $account, array $context, $entity_bundle) {
  if ($entity_bundle == 'author' && $account->hasPermission('create new authors')) {
    return AccessResult::allowed();
  }
  // No opinion.
  return AccessResult::neutral();
}

This will give explicit access to roles with your custom permission, and in other cases it will defer to the default drupal permissions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.