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.

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

zewebmaster created an issue. See original summary.

dydave’s picture

Re-rolled patch from MR !47, for stable 3.1.37.

Uploading static patch file.

jepster_’s picture

Thanks! Can you create a MR for this?

dydave’s picture

Thanks 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!

  • dydave committed 84316cf9 on 3.1.x-dev
    Issue #3452245: Improve the verification of the user field
    
jepster_’s picture

Status: Active » Fixed

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.

dydave’s picture

Super nice Peter (@jepster_)!! 🥳

Thanks for your reactivity and the credit on the issue! 🙏
Cheers!

Status: Fixed » Closed (fixed)

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