Hello,

I have simplenews installed. When opening simplenews pane on user profile, I get a fatal error from password policy:

Recoverable fatal error : Argument 1 passed to password_policy_password_element_alter() must be of the type array, null given, called in /home/oturpin/equidrup/sites/all/modules/password_policy/password_policy.module on line 261 and defined dans password_policy_password_element_alter() (ligne 201 dans /home/oturpin/equidrup/sites/all/modules/password_policy/password_policy.module).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

AohRveTPV’s picture

Does this change fix the problem?

oturpin’s picture

Hi AohRveTPV,

So quick !!! Much better. Pb solved.

Thx

AohRveTPV’s picture

Issue tags: -password policy fatal error somplenews +password policy fatal error simplenews

OK, great. I will plan to develop a better fix for commit.

The code was always trying to customize the password field for the user_register_form and user_profile_form, whether or not the password field existed on them.

AohRveTPV’s picture

Status: Active » Needs review
FileSize
1.41 KB

Same fix, but try to make code intent more explicit.

oturpin’s picture

Hi AohRveTPV,

Don't know if any link with database type... I am using Postgresql. Fix is OK for me.

Thx

  • AohRveTPV committed bed8c2c on 7.x-2.x
    Issue #2489918 by AohRveTPV, oturpin: Fatal error on user profile
    
AohRveTPV’s picture

Status: Needs review » Fixed
ron_s’s picture

This same problem exists with the Profile2 module. Looking at the patch, I'm wondering if there's a simpler way that it could be done, without hard coding user_profile_form and user_register_form in the code?

How about just setting the default array value to NULL, and skipping the function if no array is set. Seems more straightforward to me, unless I'm missing some particular case?:

function password_policy_password_element_alter(array &$element = NULL, $account) {
  if (isset($element)) {
    $items = array();
    $policies = PasswordPolicy::matchedPolicies($account);

    foreach ($policies as $policy) {
      $items = $items + $policy->messages();
    }

    // Only alter description if policy messages are present.
    if (count($items)) {
      $element['#description'] = (isset($element['#description']) ? $element['#description'] : '') .
        theme('item_list', array(
          'items' => $items,
          'title' => t('Passwords must match the following requirements -'),
          'attributes' => array(
            'id' => 'password-policy-requirements',
          ),
        ));
    }

    // Attach password evaluation logic and ensure it's added after user.js.
    $element['#attached']['js'][] = array(
      'data' => drupal_get_path('module', 'password_policy') . '/password_policy.js',
      'weight' => 10,
    );

    // Add dependency of password_policy.js.
    $element['#attached']['library'][] = array('system', 'drupal.form');

    // Add clean URL setting for use by password_policy.js.
    $clean_url = variable_get('clean_url', FALSE);
    $settings = array('cleanUrl' => $clean_url);
    $element['#attached']['js'][] = array(
      'data' => array('passwordPolicy' => $settings),
      'type' => 'setting',
    );
  }
}
ron_s’s picture

Looking a little more closely at the patch you created in #1, it's relatively close to what I added, except you're using a return to break out of the function.

I'm assuming the reason for the more lengthy approach in #4 is you're wanting to be more explicit in the solution?

AohRveTPV’s picture

This same problem exists with the Profile2 module. Looking at the patch, I'm wondering if there's a simpler way that it could be done, without hard coding user_profile_form and user_register_form in the code?

That would be ideal. I thought there could possibly be cases where $form['account']['pass'] is set but the element should not be altered. (The original authors may have hard-coded the form IDs for a reason.) So adding an extra condition seemed safest initially.

I'm not sure your proposed code change would work though. Have you tried it? On some forms, I believe $form['account'] will not be set, so accessing $form['account']['pass'] in the call to password_policy_password_element_alter() would give an error.

AohRveTPV’s picture

I'm assuming the reason for the more lengthy approach in #4 is you're wanting to be more explicit in the solution?

Yes, I wanted the purpose of the conditionals to be clearer. A problem I have had working with the code, especially the 1.x branch, is conditionals where it is unclear what they are doing or why they are necessary.

ron_s’s picture

I did try my suggestion with Profile2 and it worked as I would expect, however as you mentioned it may not work in all situations.

Certainly a case where $form['account'] is not set would be an issue.

Status: Fixed » Closed (fixed)

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

mudjunky’s picture

+1 for @ron_s #8 solution. The patches did not work for me. They fixed the fatal error, but nullified the password policy. Users could enter any password they wanted without any barrier from the password policy.

AohRveTPV’s picture

mudjunky, are you also using Profile2?

Anonymous’s picture

Status: Closed (fixed) » Needs review
FileSize
2.78 KB

Yes, with Profile2 I am receiving this error. I'm attaching a patch with the solution from #8, which fixes the problem for me.

H.

Status: Needs review » Needs work
Anonymous’s picture

Version: 7.x-2.0-alpha5 » 7.x-2.x-dev

The patch was made against the dev version, that's why it failed the tests.

Status: Needs work » Needs review

badjava’s picture

+1 on the commit in #6. While it may not be the simplest implementation as others have suggested, it does work and should $form['account'] be unset, everything still works well. This issue appears to be resolved.

@mudjunky re: #14 - Try the dev version or use the patch from it which should apply cleanly to alpha5.

AohRveTPV’s picture

Status: Needs review » Closed (fixed)

I believe this is fixed in 7.x-2.0-alpha6 and onward, without hard-coding form IDs, by the patch committed in #2562481: Apply password policies to account password elements on custom forms:
http://cgit.drupalcode.org/password_policy/commit/?id=9f69062

If you experienced this error before, please retest with 7.x-2.0-alpha6 or later, and let us know whether it still occurs. If so, we can re-open. Thanks all.