Problem/Motivation

FormBuilder::handleInputElement() contains a long condition that checks if #access is a boolean or a valid access result object:

$process_input = empty($element['#disabled']) &&
      !in_array($element['#type'], ['item', 'value'], TRUE) &&
      (
        ($form_state->isProgrammed() && $form_state->isBypassingProgrammedAccessChecks()) ||
        ($form_state->isProcessingInput() && (!isset($element['#access']) || (($element['#access'] instanceof AccessResultInterface && $element['#access']->isAllowed()) || ($element['#access'] === TRUE))))
      );

You can check here

Moving this condition to a separate method would make it easier to maintain, document and reuse.

Steps to reproduce

  1. On a Drupal up-to-date and Clean installation, create a simple form with: drush gen form
  2. Follow those prompts, and make sure your new form use a textfield '#type'
  3. Debug the $process_input var after submit any value
  4. The result should be the same before and after the changes being applyied

Proposed resolution

Create a new private method that returns a boolean.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#5 Simple_test_form.png12.19 KBigorgoncalves

Issue fork drupal-3526249

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.

ishani patel’s picture

Assigned: Unassigned » ishani patel

ishani patel’s picture

Assigned: ishani patel » Unassigned
Status: Active » Needs review

Hello,
I've created MR.
Kindly review it.

Thank you!

igorgoncalves’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new12.19 KB

thanks @IshaniPatel

The tests result was consistent after applying your code improvement.

igorgoncalves’s picture

Issue summary: View changes
igorgoncalves’s picture

Issue summary: View changes
ishani patel’s picture

Hello @prudloff,
Thanks for the review, and I updated the MR as per your suggestion.
Kindly check.

Thank you!

longwave’s picture

Status: Reviewed & tested by the community » Needs review

Added a suggestion to improve readability while we're here. Nitpicks welcome on the comments, or feel free to reject this if you don't think it's necessary at all.

smustgrave’s picture

Status: Needs review » Needs work

Appears to be 1 open thread.

prudloff’s picture

Status: Needs work » Needs review

I applied the suggestion.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

  • catch committed b8e69839 on 11.x
    Issue #3526249 by prudloff, ishani patel, longwave: Move the access...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x, thanks!

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

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

Maintainers, please credit people who helped resolve this issue.

catch’s picture

Just a note I briefly thought 'could we put this logic in a closure' - that would allow for the multi-line logic, but not for re-use, however I think there's enough here to break it out.

Status: Fixed » Closed (fixed)

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