Problem/Motivation

Since 4.0.1, I have an issue because I'm not using Masquerade on my Drupal install.

Steps to reproduce

Install Password Policy, without installing Masquerade.

Uncaught PHP Exception Error: "Call to undefined method Symfony\Component\HttpFoundation\RequestStack::isMasquerading()" at /web/modules/contrib/password_policy/src/EventSubscriber/PasswordPolicyEventSubscriber.php line 118

Proposed resolution

I don't know why, but on my install where I don't have Masquerade, $masquerade variable in constructor is returning a variable and not NULL.
var_dump on this variable gives me an object of this class:
Symfony\Component\HttpFoundation\RequestStack

One way to solve it would be to check the variable before to initialize it in PasswordPolicyEventSubscriber, line 71:
$this->masquerade = $masquerade && class_exists('\\Drupal\\masquerade\\Masquerade') && $masquerade instanceof \Drupal\masquerade\Masquerade ? $masquerade : NULL;

Remaining tasks

Nothing

User interface changes

Nothing

API changes

Nothing

Data model changes

Nothing

Thank you for your work.

CommentFileSizeAuthor
#2 password_policy-3439398.patch684 bytessarwan_verma

Comments

relisiuol created an issue. See original summary.

sarwan_verma’s picture

Assigned: relisiuol » Unassigned
Status: Active » Needs review
StatusFileSize
new684 bytes

Hi @relisiuol,

I have fixed this issue "Password Policy & Masquerade support" and also attached patch,
kindly review and verify .

relisiuol’s picture

Hi sarwan_verma,

Sadly your fix is not working because, as I said in my report, $masquerade variable in constructor is not null.

BUT, after cleaning drupal cache everything went back to normal.

Best regards,

relisiuol’s picture

Status: Needs review » Closed (works as designed)
pratishjha’s picture

The patch is not working. Still getting the error

The website encountered an unexpected error. Please try again later.
Error: Call to undefined method Drupal\Core\Http\RequestStack::isMasquerading() in Drupal\password_policy\EventSubscriber\PasswordPolicyEventSubscriber->checkForUserPasswordExpiration() (line 118 of modules\contrib\password_policy\src\EventSubscriber\PasswordPolicyEventSubscriber.php).

Do we have any solution for this?

NvisionSA’s picture

Hi pratishjha,

I have the same error as yours.
I just ran:
composer require 'drupal/masquerade:^2.0@RC'
and that solves my problem

canardesign’s picture

Not working for me either, should we downgrade password_policy ?

dianacastillo’s picture

running composer require 'drupal/masquerade:^2.0@RC' worked for me as in #6 thanks