[Drupal 11] Call to deprecated method loadRevision()

Created on 14 May 2024, 7 months ago
Updated 2 September 2024, 4 months ago

Problem/Motivation

Call to deprecated method loadRevision() of class Drupal​\​Core​\​Entity​\​EntityStorageInterface
. Deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use Drupal​\​Core​\​Entity​\​RevisionableStorageInterface::loadRevision instead.

This is found in menu_link_attributes.module line 187: https://git.drupalcode.org/project/menu_link_attributes/-/blob/8.x-1.x/m...

We need to replace this to be able to use this module in Drupal 11. Lucky for us, this RevisionableStorageInterface already exists since Drupal 8, so we can continue to use the 8.x-1.x branch to provide support for Drupal 8-11.

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇵🇹Portugal jcnventura

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

Merge Requests

Comments & Activities

  • Issue created by @jcnventura
  • Assigned to akhil_01
  • Issue was unassigned.
  • 🇩🇪Germany Anybody Porta Westfalica

    @jcnventura can you perhaps create the 2.x branch so we can create a MR against it?

  • 🇵🇹Portugal jcnventura

    I don't think that the 2.x branch is needed. RevisionableStorageInterface already exists since Drupal 8.

    But of course, I'd need to see the actual implementation of the fix.

  • 🇩🇪Germany Anybody Porta Westfalica

    On the other hand the 2.x branch would introduce SemVer so I still think it wouldn't be bad and leave 8.x-1.x as-is?

  • 🇵🇹Portugal jcnventura

    Actually, 2.x would, by introducing semver actually break semver :)

    Unless there's BC-breaking changes, a major version jump would not be semver-compliant.

  • First commit to issue fork.
  • Status changed to Needs review 6 months ago
  • 🇨🇦Canada m4olivei Grimsby, ON

    Hey there 👋. I was attempting to use menu_link_attributes to test something on Drupal 11.x and found this issue. I don't believe there is an actual problem with the code in question on Drupal 11.x or any version.

    First, it was not obvious to me how to reproduce the issue or trigger the code path in question. Here's what I found to work:

    • Checkout the latest Drupal core 11.x
    • Install Drupal w/ Umami demo (eg. drush si -y demo_umami
    • Clone the menu_link_attributes module
    • Edit the menu_link_attributes.info.yml to add || 11 to core_version_requirement
    • Enable content translation for menus. Navigate to Configuration > Region and language > Content language and translation. Enable "Custom menu link". Expand "Custom menu link", enable "Translatable" next to "Custom menu link". Enable the "Hide non translatable fields on translation forms". Click "Save configuration"
    • Create a custom menu link. Set some menu attributes.
    • Translate the custom menu link and click Save.

    After all that, the last step, saving the translated custom menu link will trigger the code path pointed out. There are no errors or warnings here when I run the module in Ddrupal 11.x. This makes sense, b/c the code here, eg.

    \Drupal::entityTypeManager()
          ->getStorage($menu_link->getEntityTypeId())

    Will load an object of type \Drupal\menu_link_content\MenuLinkContentStorage, and that class implements in it's interface hierarchy \Drupal\Core\Entity\RevisionableStorageInterface, which has the legit loadRevision method.

    I think the error you're getting is simply from static analysis. At runtime, there is no actual issue.

    Marking as Needs Review. Suggesting to Close as works as designed, and then open a follow up to get to 11.x support.

  • Assigned to Grevil
  • 🇩🇪Germany Anybody Porta Westfalica

    @grevil could you have a short look here?

  • 🇩🇪Germany Anybody Porta Westfalica
  • First commit to issue fork.
  • Issue was unassigned.
  • 🇩🇪Germany Grevil

    Yep @m4olivei is right!

    Thanks for the steps to reproduce! :)

    I added a few variable comments (and typing to menu_link_attributes_menu_link_content_form_entity_builder()), tested it and checked the upgrade_status output. Everything still works as expected and upgrade status succeeds now!

    Output before:

    FILE: web/modules/custom/menu_link_attributes/menu_link_attributes.module
    
    STATUS         LINE                           MESSAGE
    --------------------------------------------------------------------------------
    Ignore         185  Call to deprecated method loadRevision() of interface
                        Drupal\Core\Entity\EntityStorageInterface. Deprecated in
                        drupal:10.1.0 and is removed from drupal:11.0.0. Use
                        Drupal\Core\Entity\RevisionableStorageInterface::loadRevisio
                        n instead.
    --------------------------------------------------------------------------------
    

    Output after:

     [notice] Processing /var/www/html/web/modules/custom/menu_link_attributes.
    
    ================================================================================
    Menu Link Attributes, --
    Scanned on Mon, 08/19/2024 - 10:16
    
    No known issues found.
    

    Please review!

  • Status changed to RTBC 4 months ago
  • 🇩🇪Germany Anybody Porta Westfalica

    Great work @Grevil! Changes LGTM and make sense. It also makes sense to add the parameter Interface type to make things more clear and safe. Hope there won't be any drawbacks or wrong legacy use...

  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇩🇪Germany Anybody Porta Westfalica

    Just ensured that the method already exists in Drupal 8: https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!Revisionab...

    So we can keep the compatibility.

  • Pipeline finished with Skipped
    4 months ago
    #257955
  • Status changed to Fixed 4 months ago
  • 🇩🇪Germany Anybody Porta Westfalica

    Merged into dev! Thanks all!

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

Production build 0.71.5 2024