Problem/Motivation
In the new JSON-RPC module, we would like to define RPC actions as plugins. It would be useful to share common behavior, especially dependency injection and access callbacks, between these methods.
Take a simplified 'user permissions' RPC service example:
/**
* @JsonRpcMethod(
* id = "permissions.get",
* access_method = "checkAccess",
* )
*
* @JsonRpcMethod(
* id = "permissions.add",
* access_method = "checkAccess",
* . params = {
* . "permission" = "string",
* . "role" = "string",
* }
* )
class UserPermissions {
protected $permissionsHandler;
public function __construct(PermisionHandlerInterface $permission_handler) {}
public function get() {}
public function add($permission, $role) {}
public function checkAccess(AccountInterface $account) {}
}
Since methods are created via plugin annotations, it would be useful to have multiple annotations per class.
This is an existing feature of the underlying libraries.
Proposed resolution
Fix Drupal\Component\Annotation\Plugin\Discovery\AnnotatedClassDiscovery
to recognize all annotations of a particular type on a class, not just the first one found.
API changes
One class can now satisfy multiple plugins.
Data model changes
None.