Problem/Motivation

AccessResult::neutral() allows setting a reason but AccessResult::allowedIf() and AccessResult::forbiddenIf() don't allow setting a reason on the neutral result.
I think this is confusing DX. If reasons on neutral results are valuable, we should always allow setting it.

Steps to reproduce

AccessResult::neutral('This is neutral because...');

// I can't explain why this would be neutral.
AccessResult::allowedIf();

Proposed resolution

We could add a $reason parameter to allowedIf().
And pass the reason to neutral() in forbiddenIf().

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3566611

Command icon 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

prudloff created an issue. See original summary.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

prudloff’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Does seem to be a good quality of life improvement for the developers.

CR reads fine to me.

Have no additional feedback to give.

godotislate’s picture

Status: Reviewed & tested by the community » Needs work

Couple suggestions on the MR.

prudloff’s picture

Status: Needs work » Needs review

I applied the suggestions.
I had to fix some tests to avoid type errors.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Feedback appears to be addressed.

  • godotislate committed 06b4b895 on main
    feat: #3566611 It's not always possible to add a reason to neutral...

  • godotislate committed 6469cf7a on 11.x
    feat: #3566611 It's not always possible to add a reason to neutral...
godotislate’s picture

Version: main » 11.x-dev
Component: other » base system
Status: Reviewed & tested by the community » Fixed

Committed and pushed 06b4b89 to main and to 11.x. Thanks!

Published the CR.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.