Thu, 12/19/2019 - 23:13
When creating a custom entity using
drupal generate:entity:content
there is no permission for editing own entity. Assuming your entity type is names message follow these steps to enable this permission
- Add the new permission to the permission file name message.permissions.yml. Add a permission
edit own message:
title: 'Edit Own Message'
- Update the src/MessageAccessControlHandler::checkAccess as below
protected function checkAccess()
switch($opreration) {
//...
case 'update':
if($entity -> getOwnerId() === $account ->id()) {
return AccessResult::allowedIfHasPermission($account, 'edit own messages');
}
return AccessResult::allowedIfHasPermission($account, 'edit messages');
}
Authored by