Automated Drupal 10 compatibility fixes

Created on 15 June 2022, over 2 years ago
Updated 13 October 2023, about 1 year ago

Problem/Motivation

Hello project maintainers,

This is an automated issue to help make this module compatible with Drupal 10.

To read more about this effort by the Drupal Association, please read: The project update bot is being refreshed to support Drupal 10 readiness of contributed projects

Patches will periodically be added to this issue that remove Drupal 10 deprecated API uses. To stop further patches from being posted, change the status to anything other than Active, Needs review, Needs work or Reviewed and tested by the community. Alternatively, you can remove the "ProjectUpdateBotD10" tag from the issue to stop the bot from posting updates.

The patches will be posted by the Project Update Bot official user account. This account will not receive any issue credit contributions for itself or any company.

Proposed resolution

You have a few options for how to use this issue:

  1. Accept automated patches until this issue is closed

    If this issue is left open (status of Active, Needs review, Needs work or Reviewed and tested by the community) and the "ProjectUpdateBotD10" tag is left on this issue, new patches will be posted periodically if new deprecation fixes are needed.

    As the Drupal Rector project improves and is able to fix more deprecated API uses, the patches posted here will cover more of the deprecated API uses in the module.

    Patches and/or merge requests posted by others are ignored by the bot, and general human interactions in the issue do not stop the bot from posting updates, so feel free to use this issue to refine bot patches. The bot will still post new patches then if there is a change in the new generated patch compared to the patch that the bot posted last. Those changes are then up to humans to integrate.

  2. Leave open but stop new automated patches.

    If you want to use this issue as a starting point to remove deprecated API uses but then don't want new automated patches, remove the "ProjectUpdateBotD10" tag from the issue and use it like any other issue (the status does not matter then). If you want to receive automated patches again, add back the "ProjectUpdateBotD10" tag.

  3. Close it and don't use it

    If the maintainers of this project don't find this issue useful, they can close this issue (any status besides Active, Needs review, Needs work and Reviewed and tested by the community) and no more automated patches will be posted here.

    If the issue is reopened, then new automated patches will be posted.

    If you are using another issue(s) to work on Drupal 10 compatibility it would be very useful to other contributors to add those issues as "Related issues" when closing this issue.

Remaining tasks

Using the patches

  1. Apply the latest patch in the comments by Project Update Bot or human contributors that made it better.
  2. Thoroughly test the patch. These patches are automatically generated so they haven't been tested manually or automatically.
  3. Provide feedback about how the testing went. If you can improve the patch, post an updated patch here.

Providing feedback

If there are problems with one of the patches posted by the Project Update Bot , such as it does not correctly replace a deprecation, you can file an issue in the Drupal Rector issue queue . For other issues with the bot, for instance if the issue summary created by the bot is unclear, use the Project analysis issue queue .

📌 Task
Status

Fixed

Version

3.0

Component

Code

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States danflanagan8 St. Louis, US

    I'm looking into getting this module working on D10. Here's something that will need to be addressed: https://www.drupal.org/node/3187914

    I'm trying to write some tests for the module but I'm having a hard time with the csrf_token_seed

  • 🇺🇸United States danflanagan8 St. Louis, US

    I'm also seeing this as I'm building out tests.

    Calling Drupal\Core\Session\SessionManager::getId() outside of an actual existing session is deprecated in drupal:9.2.0 and will be removed in drupal:10.0.0. This is often used for anonymous users. See https://www.drupal.org/node/3006306
    

    So that's something that will need to be addressed as well. :(

  • 🇺🇸United States danflanagan8 St. Louis, US

    I made another issue for adding test coverage that I wrote as part of checking out the D10 compatibility: 📌 Add automated test coverage for anonymous_token Fixed

    The tests pass on D9.5 but with the following warnings:

      2x: Calling Drupal\Core\Session\SessionManager::getId() outside of an actual existing session is deprecated in drupal:9.2.0 and will be removed in drupal:10.0.0. This is often used for anonymous users. See https://www.drupal.org/node/3006306
        2x in AnonymousTokenTest::testAnonymousToken from Drupal\Tests\anonymous_token\Functional
    
      1x: Calling Drupal\Core\Session\MetadataBag::clearCsrfTokenSeed() is deprecated in drupal:9.2.0 and will be removed in drupal:10.0.0. Use \Drupal\Core\Session\MetadataBag::stampNew() instead. See https://www.drupal.org/node/3187914
        1x in AnonymousTokenTest::testAnonymousToken from Drupal\Tests\anonymous_token\Functional
    
    

    The test fails on D10 due to MetadataBag::clearCsrfTokenSeed being undefined. The SessionManager::getId() thing doesn't seem to cause a failure. I would still think that needs to be addressed. Sessions are not something I usually think about.

  • Status changed to Needs review almost 2 years ago
  • 🇺🇸United States danflanagan8 St. Louis, US

    Here's a patch that addresses the items in #6 and updates the core version requirement, which starts at 9.2 because that's when MetadataBag::stampNew was added.

  • 🇺🇸United States danflanagan8 St. Louis, US

    I queued the patch for testing against D10.1 and as I recalled you can't up core version requirement in a patch and run tests with the patch. I think I can open an MR and get tests to run there though so I'm going to try that.

  • @danflanagan8 opened merge request.
  • 🇺🇸United States danflanagan8 St. Louis, US

    Hooray! The tests are passing on D9.5 and D10.1. This is ready for a real review.

    I wanted to explain one change that may be a bit mysterious.

    +++ b/src/Access/AnonymousCsrfTokenGenerator.php
    @@ -68,7 +69,7 @@ class AnonymousCsrfTokenGenerator extends CsrfTokenGenerator {
       public function get($value = '') {
         if ($this->session->isStarted() === FALSE) {
    -      $this->session->set('anon_session_id', $this->session->getId());
    +      $this->session->set('anon_session_id', Crypt::randomBytesBase64());
         }
         return parent::get($value);
    

    I made this change because of the deprecation in Drupal\Core\Session\SessionManager::getId() described in #6. Per the comment with the AnonymousCsrfTokenGenerator::get() method, the important thing here is that we add SOMETHING to the sessions so that the session persists. I think we could add anything, but Crypt::randomBytesBase64() looks pretty popular in the csrf space. It doesn't look like anon_session_id has any special significance beyond just being SOMETHING that we add such that the session persists. I'm not an expert here though, to be honest.

    All the others changes should be clear though. Thanks!

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    1 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    1 pass
  • 🇮🇳India Aziza Anwari Gujarat

    Thank you so much @danflanagan8 for this beautiful patch, have tried it for 2.x-dev, and works well
    moving it to RTBC

    Attaching upgrade status report image, that it makes it compatible with drupal 10

  • Status changed to RTBC over 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    1 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    1 pass
  • 🇮🇳India Aziza Anwari Gujarat

    Adding patch version as well for immediate use,
    inspired by the #9 merge request from danflanagan8

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    Composer require failure
  • 🇧🇪Belgium baikho Antwerp, BE

    Thanks all, I'm adding a new major version branch, given the Core deprecations.

  • Status changed to Fixed about 1 year ago
  • 🇧🇪Belgium baikho Antwerp, BE
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024