- Issue created by @penyaskito
- First commit to issue fork.
- 🇮🇳India libbna New Delhi, India
I initially tried this code:
'view' => AccessResult::allowedIf($account->isAuthenticated()) ->addCacheContexts(['user.roles:authenticated']) ->setReason('....'),
However, when accessing the path /xb/api/v0/config/js_component/xxxx as an authenticated user, it threw the following error:
Call to undefined method Drupal\Core\Access\AccessResultAllowed::setReason()
After checking, I realized that setReason() only works with AccessResult::forbidden(), not with AccessResultAllowed.
I then updated the code to apply setReason() only when access is denied. After this change, I tested the api.config.get endpoint as an anonymous user and was able to see the error message with the reason.
Please let me know if the message shown is appropriate or if any further changes are needed.