Entity Type Access Conditions
A Drupal module that allows you to control access to entity types and their bundles based on configurable conditions.
Overview
Entity Type Access Conditions provides a flexible way to control access to entity types on your Drupal site. This module allows you to restrict operations like create, view, update, and delete for entity types and bundles based on various conditions. For example, you could restrict the creation of a specific content type to users with a certain role, or only on certain domains.
This module works by adding a set of configurable conditions to the configuration forms of entity types. Out of the box, it supports:
- Node Types
- Media Types
- Taxonomy Vocabularies
Requirements
- Drupal 10.x or 11.x
- Conditions Helper
Installation
Install as you would normally install a contributed Drupal module. For further information, see Installing Drupal Modules.
Configuration
Admin Settings
The module provides an administration page to control which conditions are available for entity type access at:
Administration > Configuration > Content > Entity Type Access Conditions
From this page, administrators with the 'administer entity type access conditions' permission can select which conditions should be available when configuring entity access.
Entity Type Settings
When enabled, the module will add access condition settings automatically to the configuration forms for supported entity types (e.g., Node Types).
Usage
- Navigate to the configuration form for any supported entity type. For example for a Node Type, go to Structure > Content types and edit a content type.
- Look for the "Entity Type Access Conditions" section.
- Add one or more conditions that determine when access should be granted.
- Configure the condition parameters as needed.
- Save the configuration.
Users who do not meet the configured conditions will not be able to perform restricted operations on that entity type or its bundles. Users with the 'bypass entity type access conditions' permission will always have access.
Extending the Module
This module provides a plugin system to define which entity types should have
access conditions. Developers can add support for new entity types by creating
a YAML file in their own module named
my_module.entity_type_access_conditions.yml
.
In this file, you can define the entity type, the forms to alter, and which operations should be restricted.
For example, to add support for a custom entity type my_entity_type
:
my_entity_type:
label: 'My Entity Type'
altered_forms:
- my_entity_type_edit_form
- my_entity_type_add_form
restricted_operations:
- view
- update
- delete
Additionally, developers can dynamically alter the list of forms that are altered using the provided hook:
/**
* Implements hook_entity_type_access_conditions_form_ids_alter().
*/
function my_module_entity_type_access_conditions_form_ids_alter(array
&$form_ids): void {
// Add support for another entity type form.
$form_ids[] = 'some_other_form_id';
}
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This module is licensed under the same terms as Drupal core.