Issue #3195029: Use the AccessResultForbidden reason in BulkForm error messages
Merge request reports
Activity
added 1 commit
- 0c4ef555 - Return the requested type in BatchUserAction->access().
392 392 continue; 393 393 } 394 394 // Skip execution if the user did not have access. 395 if (!$action->getPlugin()->access($entity, $this->view->getUser())) { 395 $access_result = $action->getPlugin()->access($entity, $this->view->getUser(), TRUE); 396 if (!$access_result->isAllowed()) { 397 // Use the reason if one is specified. 398 if ($access_result instanceof AccessResultReasonInterface) { 399 $reason = $access_result->getReason(); 400 if (!empty($reason)) { 401 $this->messenger->addError($reason); I'm wondering if what you want here is a combination of the generic message "No access to execute..." and the specific message, rather than the bare specific message? Because you're kind of depending on the AccessResult having a complete message in it that includes information about the item that you cannot execute the action on.
???
Yes! This is like option #2 I had in my proposal, append the
reason
to the generic message. It seems like a larger question of how the AccessResultreason
should be used in general.. and depending on the AccessResult to have the complete message means thatreason
cannot be used in other contexts.For example, this same
reason
could be used in the error message when deleting an entity via the API.This approach would work best for the reasons added in this issue: https://www.drupal.org/project/drupal/issues/2952544
I'll try this out..
changed this line in version 3 of the diff
392 392 continue; 393 393 } 394 394 // Skip execution if the user did not have access. 395 if (!$action->getPlugin()->access($entity, $this->view->getUser())) { 395 $access_result = $action->getPlugin()->access($entity, $this->view->getUser(), TRUE); 396 if (!$access_result->isAllowed()) { 397 // Use the reason if one is specified. 398 if ($access_result instanceof AccessResultReasonInterface) { 399 $reason = $access_result->getReason(); 400 if (!empty($reason)) { 401 $this->messenger->addError($reason); 402 continue; 403 } 404 } 405 // Else use the normal message. changed this line in version 3 of the diff