Automated Drupal 10 compatibility fixes

Created on 15 June 2022, over 2 years ago
Updated 11 November 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

Needs work

Version

2.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.

  • πŸ‡¨πŸ‡·Costa Rica maxmendez

    Hi, there is any plan to merge it and create a new release compatible with D10?

  • πŸ‡¨πŸ‡·Costa Rica maxmendez

    I've tested the patch and scan by my own and found another compatibility, here my patch to turn the module Drupal 10 compatible.

  • πŸ‡¨πŸ‡·Costa Rica maxmendez

    Hi @icurk and @RokSiEu,

    Sorry for tagged you but some of you can review this patch and release a new version D10 compatible.

    Thanks for your time and help.

  • Status changed to RTBC over 1 year ago
  • Status changed to Needs work about 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia darvanen Sydney, Australia

    @MaxMendez for future reference typically you shouldn't RTBC your own patches, even core committers make sure someone else looks at code if they've touched it in any way other than to maybe add a period to a comment :)

    That said, I've used this patch on a project, and it got unstuck so that's a great start. Here is a code review:

    1. +++ b/context_groups.info.yml
      @@ -1,7 +1,7 @@
      +core_version_requirement: ^8.8 || ^9 || ^10
      

      Perhaps it's time to drop support for Drupal 8? Drupal 9 is EOL but it's useful to keep it for at least one version to provide an upgrade path.

    2. +++ b/src/Form/GroupAddForm.php
      @@ -200,7 +200,7 @@ class GroupAddForm extends FormBase {
      +    $query = $this->entityTypeManager->getStorage('context')->getQuery()->accessCheck(FALSE);
      

      I'm not convinced the accessCheck should be skipped on this query. The groupExists method is a public method on a regular (read non-internal) class, and as much as it **really shouldn't** be, I think it could be used by others' custom code.

      I think the method should be made private, or the accessCheck invoked.

  • πŸ‡¨πŸ‡¦Canada adam-vessey PE, Canada

    @darvanen: The ::groupExists() method is a callback for the machine name element of the form ( https://git.drupalcode.org/project/context_groups/-/blob/fc7d8209b00a851... ), and as such is more concerned with determining if a given name is unique on the given site. Uniqueness can't really be evaluated if some results are filtered from the query, so ::accessCheck(FALSE) probably makes the most sense; otherwise, it might be possible for different users who can't see each others contexts to bind the same name, and make a mess for _other_ users who can see both? Otherwise, it seems like we would have to get into some kind of namespacing to define "uniqueness" domains? Seems like something of a rather larger overhaul of the module than we're looking to do here.

    As for the method's visibility, I've gotta admit that PHP's callable/callback-passing semantics are a little fuzzy to me: If it _was_ defined as protected/private, would it be usable as a callback for the machine name element? Looks like there's a call to the "exists" callback in MachineName::validateMachineName() ( https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21... ), which means that it would be trying to call this method that it strictly should not be able to see, but that it was passed by something that _can_ see it? Will the callback expressed as an array of object and method, I'm not sure that visibility could correctly be resolved... maybe it would be ignored? Bit of naive testing indicates that it is not possible:

    <?php
    class A {
      public function methodOne() {
        echo "one... ";
        return [$this, 'methodTwo'];
      }
    
      protected function methodTwo() {
        echo "two... ";
      }
    }
    
    $instance = new A();
    
    $callable = $instance->methodOne();
    call_user_func($callable);
    

    Resulting in:

    one... 
    Fatal error: Uncaught TypeError: call_user_func(): Argument #1 ($callback) must be a valid callback, cannot access protected method A::methodTwo() in /home/user/scripts/code.php:16
    Stack trace:
    #0 {main}
      thrown in /home/user/scripts/code.php on line 16
    

    With the newer first-class callback syntax introduced in PHP 8.1 (with $this->methodTwo(...) instead of [$this, 'methodTwo']), it _does_ appear to be possible; however, such seems to be getting rather outside of the intended scope of this issue.

  • πŸ‡¦πŸ‡ΊAustralia darvanen Sydney, Australia

    @adam-vessey

    Uniqueness can't really be evaluated if some results are filtered from the query

    Very good point, bad idea to set the access check then.

    As for the private/protected method, I love how you approached it. I'm afraid I don't know the answer to that. I'm quite new to this module (performing an upgrade) so I'm not familiar with where this form gets used, seems to be an AJAX call but I ran out of time to investigate further. I tried adding a breakpoint there but it wasn't triggered by the Add or Edit Context form submissions.

    seems to be getting rather outside of the intended scope of this issue

    Yeah maybe, I just wanted to raise it since the access checks are being introduced for very good reasons and I would prefer not to lose the security hardening opportunity that this represents. But simply adding ->accessCheck(FALSE) does preserve current functionality. I'm not going to kick up a fuss if that does go in.

  • πŸ‡¨πŸ‡·Costa Rica maxmendez

    Hi @darvanen, as you can see the change of status was a month later of the path, but no one cared about this module for month, but now when time is short it is easy come and talk about the work of others.

    Why donΒ΄t drop D8 support?, the original didn't and was my mistake did not drop that moment. Be free to improve and create a pr or patch to help to get a new release soon.

    Why the desition of accessCheck(FALSE)?
    Well, really thanks @darvanen of time of review and testing in how the the module work and conclude what makes the most sense.

  • πŸ‡¦πŸ‡ΊAustralia darvanen Sydney, Australia

    @MaxMendez I meant no disrespect, it’s just the process for getting work committed in core and most contributed modules.

    If I adjust the code then I am no longer in a position to review it.

    You are right, time is short, but I did not know about this module until a few days ago, I’m not responsible for the response time of the current maintainers, who are volunteering their time just like you and me πŸ™‚

    I’m afraid I don’t have all the answers regarding the access check. I don’t even fully understand what this module does yet. Did the missing access check cause an error? What were you doing when it did?

Production build 0.71.5 2024