[10.2] user_roles() and user_role_names() are deprecated

Created on 25 June 2024, 6 months ago
Updated 13 July 2024, 6 months ago
📌 Task
Status

Fixed

Version

4.0

Component

Rules Core

Created by

🇺🇸United States tr Cascadia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @tr
  • Assigned to sarwan_verma
  • Issue was unassigned.
  • Status changed to Needs review 6 months ago
  • 🇮🇳India sarwan_verma

    Hi @TR,

    I've created the patch for this , please verify the attached patch.

  • Status changed to Needs work 6 months ago
  • 🇺🇸United States tr Cascadia
         // Use parameter FALSE to include 'Anonymous'.
    -    $roles = user_role_names(FALSE);
    +    $roles = Role::loadMultiple(FALSE);

    This doesn't work.

    loadMultiple() doesn't take a boolean argument.
    You have to make sure that the value of $roles doesn't change. I suggest reading the change record that I linked.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update 6 months ago
    292 pass, 92 fail
  • Status changed to Needs review 6 months ago
  • 🇮🇳India sarwan_verma

    I have added the new updated patch ,kindly review and verify. Thanks.

  • Status changed to Needs work 6 months ago
  • 🇺🇸United States tr Cascadia

    Read what I said in #4.

  • First commit to issue fork.
  • 🇮🇳India ankitv18

    ankitv18 → changed the visibility of the branch 3457135-10.2-userroles-and to hidden.

  • Pipeline finished with Failed
    6 months ago
    Total: 580s
    #208907
  • Status changed to Needs review 6 months ago
  • 🇮🇳India ankitv18

    MR!38 is ready for review

  • Status changed to Needs work 6 months ago
  • 🇺🇸United States tr Cascadia

    Again, user_role_names() and Role::loadMultiple() DO NOT GENERATE THE SAME OUTPUT. You can't simply substitute one for the other. More work needs to be done.

    The contents of $roles needs to be EXACTLY THE SAME after the change as it was before the change.

    Here is a little drush script that demonstrates this is wrong. This prints the value of $roles with the old code then prints the value of $roles with the new code. Run this as drush php-script 3457135-roles.txt

  • Assigned to bharath-kondeti
  • 🇮🇳India bharath-kondeti Hyderabad
  • Issue was unassigned.
  • Status changed to Needs review 6 months ago
  • 🇮🇳India bharath-kondeti Hyderabad
  • Pipeline finished with Failed
    6 months ago
    Total: 663s
    #209223
  • 🇺🇸United States tr Cascadia

    I don't think Html::escape() is correct here, so I removed it. The original function user_role_names() does not use it. Also, this was discussed in the core issue linked in the change notice. Although the core patch did use it in some places, there was a follow-up issue to remove it.

    Regardless, in Rules, this code appears in an OptionsProvider, and sanitation should not take place this early - that should be left to the rendering stage. We have no knowledge in the OptionsProvider about how the data will eventually be used, so IMO it is premature to modify it with escape().

  • 🇮🇳India bharath-kondeti Hyderabad

    Okay. Thanks for the review. @TR do we have to address the build issues on PR in this issue itself ?

  • Pipeline finished with Skipped
    6 months ago
    #211399
  • Status changed to Fixed 6 months ago
  • 🇺🇸United States tr Cascadia

    Only need to address things caused by this MR, but there are none. I still trying to get all the tests back and running - they're failing due to changed in D10.3 and due to the change from DrupalCI to GitLabCI. I'm working on it, and it's almost all fixed now.

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

Production build 0.71.5 2024