Problem/Motivation
First of all, thank you very much for your module.
In the case of my application, I have to disable the 'user' field in a hook_form_taxonomy_term_form_alter(), because I want to limit the choice only to roles.
function HOOK_form_taxonomy_term_form_alter(&$form, FormStateInterface $formState, $formId): void {
unset($form['access']['user']);
}
However, when I edit a term and validate, I get an warning message.
Warning: Undefined array key "access" in Drupal\permissions_by_term\Service\AccessStorage->getSubmittedUserIds() (line 371 of modules/contrib/permissions_by_term/src/Service/AccessStorage.php).
I have tried many ways :
* with unset($form['access']['user']);
* with $form['access']['user']['#access'] = FALSE;
* with $form['access']['user']['#attributes']['disabled'] = TRUE;
But whatever method I choose, I still get this error message because the field is disabled and Drupal doesn't send it in the request.
Steps to reproduce
To reproduce this problem easily, simply :
* Configure a vocabulary so that permission can be applied to it.
* Implement in a hook_form_taxonomy_term_form_alter().
* Deactivate the user field, as shown in the description of the bug
* Modify a term and submit.
Proposed resolution
The method getSubmittedUserIds() in the AccessStorage service handles the Drupal response in a very strange way, as documented, but I don't know enough about the module to understand why. Nevertheless, this problem can be corrected very simply, in one line, by making sure that the 'user' entry exists in the request table.
# \Drupal\permissions_by_term\Service\AccessStorage::getSubmittedUserIds()
$sRawUsers = $_REQUEST['access']['user'] ?? [];
I'm well aware that the case of my application is specific. Nevertheless, this refinement makes the module code more robust and may prevent other errors in similar circumstances.
Remaining tasks
Nothing, I'm proposing an MR.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 3452245-3-permissions_by_term-fix-accessstorage-service.patch | 571 bytes | dydave |
Issue fork permissions_by_term-3452245
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
Comment #3
dydave commentedRe-rolled patch from MR !47, for stable 3.1.37.
Uploading static patch file.
Comment #4
jepster_Thanks! Can you create a MR for this?
Comment #5
dydave commentedThanks Peter (@jepster_) for the prompt and positive follow-up on this issue, it's greatly appreciated.
Just a quick reply to let you know the merge request MR!47 was just updated with the changes suggested in the patch #3.
Leaving in Active for now, at the appreciation of the module maintainers.
Feel free to review and let us know if you have any comments, suggestions or questions, we would certainly be happy to help.
Thanks in advance!
Comment #7
jepster_Released in 3.1.38: https://www.drupal.org/project/permissions_by_term/releases/3.1.38
Comment #9
dydave commentedSuper nice Peter (@jepster_)!! 🥳
Thanks for your reactivity and the credit on the issue! 🙏
Cheers!