Problem/Motivation
There are cases when a field permissions plugin needs to be applied only on some specific fields or on specific entity types. For instance, we want to implement a custom FieldPermissionType
plugin that should be available only for user
entity type fields, because of its business logic. There's no API to do that in a clean way. With the current code, a 3rd party module, should hack into the field config edit form and remove the plugin when it doesn't apply to that particular field. Also the ::hasFieldAccess()
should make all checks if the plugin should handle that kind of field.
But we can do better...
Use-case
Here's a module that already uses this (proposed) feature: User Fields Visibility
Steps to reproduce
N/A
Proposed resolution
- Add a new
FieldPermissionTypeInterface::appliesToField()
method that takes as argument the field definition and returns a boolean. - Implement
Base::appliesToField()
, always returningTRUE
. - In
FieldPermissionsService::getFieldAccess()
andFieldPermissionsService::hasFieldViewAccessForEveryEntity()
use the new method. - In
field_permissions_form_field_config_edit_form_alter()
don't show the plugins that are not passing theFieldPermissionTypeInterface::appliesToField()
check.
Remaining tasks
None.
User interface changes
Plugins not passing FieldPermissionTypeInterface::appliesToField()
are not displayed.
API changes
New method FieldPermissionTypeInterface::appliesToField()
.
Data model changes
None.
Issue fork field_permissions-3228881
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
claudiu.cristeaComment #4
claudiu.cristeaFixing credit attribution.
Comment #5
Andras_Szilagyi CreditAttribution: Andras_Szilagyi for European Commission and European Union Institutions, Agencies and Bodies commentedWorks as descibed
Comment #6
claudiu.cristeaUpdate IS with a use case
Comment #7
claudiu.cristeaComment #10
japerryThanks for the feature, and the test! Committed.
Comment #12
osopolarEdit: Wrong link.
Comment #13
osopolar