- Issue created by @zewebmaster
- Merge request !47Issue #3452245: Improve the verification of the user field → (Open) created by zewebmaster
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.
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.
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.
Nothing, I'm proposing an MR.
Active
3.1
Code