Drupal 10 compatibility

Created on 19 January 2024, 11 months ago
Updated 29 January 2024, 11 months ago

Problem/Motivation

This module isn't support Drupal 10 core. Let's do this module compatible with Drupal 10

Steps to reproduce

Install module on Drupal 10 and give fatal error:

The website encountered an unexpected error. Please try again later.
Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException: Circular reference detected for service "authentication_subscriber", path: "authentication_subscriber -> authentication -> authentication_collector -> domain_role.authentication.domain_cookie". in Drupal\Component\DependencyInjection\Container->get() (line 147 of core/lib/Drupal/Component/DependencyInjection/Container.php).
Drupal\Component\DependencyInjection\Container->get() (Line: 105)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 240)
Symfony\Component\HttpKernel\HttpKernel->handleThrowable() (Line: 91)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 704)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Proposed resolution

Refactor code and do compatible this module with Drupal 10.

πŸ“Œ Task
Status

RTBC

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine ankondrat4 Lutsk

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

Merge Requests

Comments & Activities

  • Issue created by @ankondrat4
  • Merge request !2Issue #3415984 | Drupal 10 compatibility β†’ (Merged) created by ankondrat4
  • πŸ‡ΊπŸ‡ΈUnited States freelock Seattle

    Hi,

    Does this change require Drupal 10 only? I see you've removed the 8 and 9 compatibility from the info file...

    Cheers,
    John

  • πŸ‡ΊπŸ‡¦Ukraine ankondrat4 Lutsk

    Hi @freelock

    Yes, this version only for Drupal 10, because we have DomainCookie that extends from class Cookie. Class Cookie in D10 has three arguments, but in D8-9 had only 2 arguments.

    D10
    https://api.drupal.org/api/drupal/core!modules!user!src!Authentication!P...

    
      /**
       * Constructs a new cookie authentication provider.
       *
       * @param \Drupal\Core\Session\SessionConfigurationInterface $session_configuration
       *   The session configuration.
       * @param \Drupal\Core\Database\Connection $connection
       *   The database connection.
       * @param \Drupal\Core\Messenger\MessengerInterface $messenger
       *   The messenger.
       */
      public function __construct(SessionConfigurationInterface $session_configuration, Connection $connection, MessengerInterface $messenger) {
        $this->sessionConfiguration = $session_configuration;
        $this->connection = $connection;
        $this->messenger = $messenger;
      }
    

    D8-D9
    https://api.drupal.org/api/drupal/core%21modules%21user%21src%21Authenti...

      /**
       * Constructs a new cookie authentication provider.
       *
       * @param \Drupal\Core\Session\SessionConfigurationInterface $session_configuration
       *   The session configuration.
       * @param \Drupal\Core\Database\Connection $connection
       *   The database connection.
       */
      public function __construct(SessionConfigurationInterface $session_configuration, Connection $connection) {
        $this->sessionConfiguration = $session_configuration;
        $this->connection = $connection;
      }
    
  • πŸ‡ͺπŸ‡ͺEstonia drugan

    Doesn't that violate the dependency injection requirement?

    The DomainCookie::getUserFromSession() method is called on each page view, so it may become a performance issue.

    Anyway, if we go the way suggested, then the DomainCookie::__construct() method can be omitted at all.

  • Issue was unassigned.
  • πŸ‡ΊπŸ‡¦Ukraine ankondrat4 Lutsk
  • πŸ‡ΊπŸ‡¦Ukraine ankondrat4 Lutsk

    Hello.

    Compatible with Drupal 10 was applied.
    When we tried to use DI of service @domain.negotiator, we got Fatal error as described in description of task. Maybe someone has solution, you are welcome to change this)

    Please, review.

  • Status changed to Needs review 11 months ago
  • πŸ‡ΊπŸ‡¦Ukraine ankondrat4 Lutsk
  • Status changed to Needs work 11 months ago
  • πŸ‡ͺπŸ‡ͺEstonia drugan

    @ankondrat4

    I think there should be some other way to fix the Circular reference fatal.

    Also, because of the issue name we need to fix all Drupal 10 compatibility errors, not just that fatal:

    drugan@multidomains-web:/var/www/html$ vendor/bin/phpstan analyze --level=0 web/modules/contrib/domain_role
    Note: Using configuration file /var/www/html/phpstan.neon.
     7/7 [β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“] 100%
    
     ------ ------------------------------------------------------------------------------ 
      Line   domain_role.module                                                            
     ------ ------------------------------------------------------------------------------ 
      104    Construct empty() is not allowed. Use more strict comparison.                 
      114    Call to function in_array() requires parameter #3 to be set.                  
      115    Implicit array creation is not allowed - variable $newroles might not exist.  
      118    Implicit array creation is not allowed - variable $newroles might not exist.  
      133    Construct empty() is not allowed. Use more strict comparison.                 
     ------ ------------------------------------------------------------------------------ 
    
     ------ ------------------------------------------------------------------------- 
      Line   src/Authentication/Provider/DomainCookie.php                             
     ------ ------------------------------------------------------------------------- 
      37     Only booleans are allowed in an if condition, mixed given.               
      45     Construct empty() is not allowed. Use more strict comparison.            
      55     Call to deprecated function user_roles():                                
             in drupal:10.2.0 and is removed from drupal:11.0.0. Use                  
               \Drupal\user\Entity\Role::loadMultiple() and, if necessary, an inline  
               implementation instead.                                                
      58     Call to function in_array() requires parameter #3 to be set.             
      58     Call to function in_array() requires parameter #3 to be set.             
      63     Call to function in_array() requires parameter #3 to be set.             
     ------ ------------------------------------------------------------------------- 
    
     ------ ------------------------------------------------------------------------------ 
      Line   src/Entity/DomainUser.php                                                     
     ------ ------------------------------------------------------------------------------ 
      38     Call to deprecated function user_role_names():                                
             in drupal:10.2.0 and is removed from drupal:11.0.0. Use                       
               \Drupal\user\Entity\Role::loadMultiple() and, if necessary, an inline       
               implementation instead.                                                     
      52     Call to function in_array() requires parameter #3 to be set.                  
      52     Call to function in_array() requires parameter #3 to be set.                  
      74     Call to function in_array() requires parameter #3 to be set.                  
      80     Call to function in_array() requires parameter #3 to be set.                  
      86     Method Drupal\domain_role\Entity\DomainUser::addRole() should return          
             $this(Drupal\domain_role\Entity\DomainUser) but return statement is missing.  
      101    Call to function in_array() requires parameter #3 to be set.                  
      103    Method Drupal\domain_role\Entity\DomainUser::removeRole() should return       
             $this(Drupal\domain_role\Entity\DomainUser) but return statement is missing.  
      120    Call to function in_array() requires parameter #3 to be set.                  
      123    Call to function in_array() requires parameter #3 to be set.                  
      129    Call to function in_array() requires parameter #3 to be set.                  
      135    Variable property access on $this(Drupal\domain_role\Entity\DomainUser).      
      136    Variable property access on $this(Drupal\domain_role\Entity\DomainUser).      
     ------ ------------------------------------------------------------------------------ 
    
     ------ ---------------------------------------------------------------------------------------------------- 
      Line   tests/src/Functional/LoadTest.php                                                                   
     ------ ---------------------------------------------------------------------------------------------------- 
      32     Return type mixed of method Drupal\Tests\domain_role\Functional\LoadTest::setUp() is not covariant  
             with return type void of method Drupal\Tests\BrowserTestBase::setUp().                              
     ------ ---------------------------------------------------------------------------------------------------- 
    
     -- ------------------------------------------------------------------------------------------------------ 
         Error                                                                                                 
     -- ------------------------------------------------------------------------------------------------------ 
         Ignored error pattern #^Dynamic call to static method PHPUnit\\Framework\\Assert# was not matched in  
         reported errors.                                                                                      
     -- ------------------------------------------------------------------------------------------------------ 
    
                                                                                                                   
     [ERROR] Found 26 errors                                                                                       
                                                                                                       
    
  • πŸ‡ΊπŸ‡¦Ukraine ankondrat4 Lutsk

    I have fixed phpcs issues

  • πŸ‡ΊπŸ‡ΈUnited States freelock Seattle

    Creating a new major version, since Drupal 9 is no longer supported with this change.

  • Pipeline finished with Skipped
    11 months ago
    #81009
  • πŸ‡ΊπŸ‡ΈUnited States freelock Seattle

    Merging in for further review and testing, thanks for your work on this!

  • Status changed to Needs review 11 months ago
  • πŸ‡ͺπŸ‡ͺEstonia drugan

    The MR !3 properly injects dependencies without causing the Circular reference fatal.

  • Status changed to RTBC 11 months ago
  • πŸ‡ΊπŸ‡¦Ukraine ankondrat4 Lutsk

    Hello.

    RTBC +1 for MR !3

Production build 0.71.5 2024