Problem/Motivation

I want to create a form where I can list the users that can masquerade as a specific target user. However, masquerade_target_user_access() only has a parameter for the target user, and it assumes that I want to check the current user's access. This means I would need to copy the code into a custom function to allow checking for a different user.

Steps to reproduce

masquerade_target_user_access() doesn't have a parameter for user to check access for.

Proposed resolution

It would be simple to add a parameter and have it default to the current user if no value is passed.

Before

function masquerade_target_user_access(UserInterface $target_account) {
  $user = \Drupal::currentUser();

After

function masquerade_target_user_access(UserInterface $target_account, ?UserInterface $user = NULL) {
  if ($user === NULL) {
    $user = \Drupal::currentUser();
  }

Remaining tasks

In addition, this function should probably be moved into the service class, so that services can be injected from the container.

User interface changes

API changes

Data model changes

Issue fork masquerade-3528686

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

solideogloria created an issue. See original summary.

solideogloria’s picture

Issue summary: View changes
solideogloria’s picture

Issue summary: View changes
solideogloria’s picture

Issue summary: View changes
chhavi.sharma’s picture

Assigned: Unassigned » chhavi.sharma

chhavi.sharma’s picture

Assigned: chhavi.sharma » Unassigned
Status: Active » Needs review
solideogloria’s picture

Status: Needs review » Reviewed & tested by the community

Looks great!