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
- On a Drupal up-to-date and Clean installation, create a simple form with:
drush gen form
- Follow those prompts, and make sure your new form use a textfield '#type'
- Debug the
$process_input var after submit any value
- 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
Comments
Comment #2
ishani patel commentedComment #4
ishani patel commentedHello,
I've created MR.
Kindly review it.
Thank you!
Comment #5
igorgoncalves commentedthanks @IshaniPatel
The tests result was consistent after applying your code improvement.
Comment #6
igorgoncalves commentedComment #7
igorgoncalves commentedComment #8
ishani patel commentedHello @prudloff,
Thanks for the review, and I updated the MR as per your suggestion.
Kindly check.
Thank you!
Comment #9
longwaveAdded 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.
Comment #10
smustgrave commentedAppears to be 1 open thread.
Comment #11
prudloff commentedI applied the suggestion.
Comment #12
longwaveLooks good to me.
Comment #14
catchCommitted/pushed to 11.x, thanks!
Comment #17
catchJust 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.