Problem/Motivation

I noticed there are quite some deprecations in the module, some of which actually prevent D9 usage.

Screenshot of deprecated code report

Steps to reproduce

Run the deprecated PHP code report on the module.

Proposed resolution

Refactor all code so the deprecations are resolved.

Remaining tasks

- Resolve deprecations in .drush.inc
- Resolve deprecations in .module
- Resolve deprecations in WidgetBlockLazyBuilder
- Resolve deprecations in WidgetBlockListBuilder

User interface changes

None

API changes

None

Data model changes

None

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

BramDriesen created an issue. See original summary.

stefaniev’s picture

+1 for this. Deprecations prevent usage in D9.

bramdriesen’s picture

Issue tags: +Novice

Tagging it as novice since it's not a difficult task.

bramdriesen’s picture

Title: Fix deprecations » Drupal 9 Compatibility: Fix deprecations
Issue tags: +Drupal 9 compatibility
anjali rathod’s picture

Assigned: Unassigned » anjali rathod
anjali rathod’s picture

Assigned: anjali rathod » Unassigned
Status: Active » Needs review
StatusFileSize
new3.83 KB

Please review and add comments . I have made changes and added a patch.

bramdriesen’s picture

Status: Needs review » Needs work

For Drupal versions 8.4+ & 9 we need to support Drush 9/10 (best to go for 10). This means the drush command needs to be refactored as well since it's no longer working with .inc files.

grgcrlsn321’s picture

@Anjali Rathod

I ran your patch, but received the following errors,

Checking patch src/WidgetBlockLazyBuilder.php...
Checking patch src/WidgetBlockListBuilder.php...
Checking patch widget_block.drush.inc...
error: while searching for:
<?php
/**
* @file
* Widget Block drush integration.

error: patch failed: widget_block.drush.inc:1
error: widget_block.drush.inc: patch does not apply

But then ran the same command with, git apply -v --reject --whitespace=fix

and everything looks good that applied, I will check with drupal-check command

Checking patch src/WidgetBlockLazyBuilder.php...
Checking patch src/WidgetBlockListBuilder.php...
Checking patch widget_block.drush.inc...
error: while searching for:
<?php
/**
* @file
* Widget Block drush integration.

error: patch failed: widget_block.drush.inc:1
Hunk #2 succeeded at 62 (offset -2 lines).
Hunk #3 succeeded at 77 (offset -2 lines).
Hunk #4 succeeded at 99 (offset -2 lines).
Hunk #5 succeeded at 124 (offset -2 lines).
Hunk #6 succeeded at 155 (offset -2 lines).
Applied patch src/WidgetBlockLazyBuilder.php cleanly.
Applied patch src/WidgetBlockListBuilder.php cleanly.
Applying patch widget_block.drush.inc with 1 reject...
Rejected hunk #1.
Hunk #2 applied cleanly.
Hunk #3 applied cleanly.
Hunk #4 applied cleanly.
Hunk #5 applied cleanly.
Hunk #6 applied cleanly.

grgcrlsn321’s picture

Before patch applied errors with drupal-check

4/4 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 ------ ----------------------------------------------------------------------- 
  Line   src/WidgetBlockLazyBuilder.php                                         
 ------ ----------------------------------------------------------------------- 
  29     Parameter $entity_manager of method                                    
         Drupal\widget_block\WidgetBlockLazyBuilder::__construct() has invalid  
         typehint type Drupal\Core\Entity\EntityManagerInterface.               
  29     Parameter $entity_manager of method                                    
         Drupal\widget_block\WidgetBlockLazyBuilder::__construct() has invalid  
         typehint type Drupal\Core\Entity\EntityManagerInterface.               
  31     Call to method getStorage() on an unknown class                        
         Drupal\Core\Entity\EntityManagerInterface.                             
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols     
  61     If condition is always true.                                           
  66     Ternary operator condition is always true.                             
 ------ ----------------------------------------------------------------------- 

 ------ -------------------------------------------- 
  Line   src/WidgetBlockListBuilder.php              
 ------ -------------------------------------------- 
  46     Call to an undefined method                 
         Drupal\Core\Entity\EntityInterface::url().  
 ------ -------------------------------------------- 

 ------ -------------------------------------------------------------------- 
  Line   widget_block.drush.inc                                              
 ------ -------------------------------------------------------------------- 
  65     Function drush_get_option not found.                                
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols  
  69     Function _drush_widget_block_get_id_option() should return          
         array<Drupal\widget_block\Entity\WidgetBlockConfigInterface> but    
         returns array<Drupal\Core\Entity\EntityInterface>.                  
  80     Function drush_get_option not found.                                
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols  
  102    Function drush_get_option not found.                                
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols  
  127    Function drush_log not found.                                       
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols  
  158    Function drush_log not found.                                       
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols  
 ------ -------------------------------------------------------------------- 

 ------ --------------------------------------------------------- 
  Line   widget_block.module                                      
 ------ --------------------------------------------------------- 
  146    PHPDoc tag @param references unknown parameter: $forced  
 ------ --------------------------------------------------------- 

 [ERROR] Found 13 errors                                     

After patch was applied,

4/4 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 ------ -------------------------------------------- 
  Line   src/WidgetBlockLazyBuilder.php              
 ------ -------------------------------------------- 
  61     If condition is always true.                
  66     Ternary operator condition is always true.  
 ------ -------------------------------------------- 

 ------ ----------------------------------------------------------------------- 
  Line   widget_block.drush.inc                                                 
 ------ ----------------------------------------------------------------------- 
  65     Call to static method input() on an unknown class Drush.               
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols     
  69     Function _drush_widget_block_get_id_option() should return             
         array<Drupal\widget_block\Entity\WidgetBlockConfigInterface> but       
         returns array<Drupal\Core\Entity\EntityInterface>.                     
  80     Call to static method input() on an unknown class Drush.               
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols     
  102    Call to static method input() on an unknown class Drush.               
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols     
  127    Static method Drupal::logger() invoked with 2 parameters, 1 required.  
  158    Static method Drupal::logger() invoked with 2 parameters, 1 required.  
 ------ ----------------------------------------------------------------------- 

 ------ --------------------------------------------------------- 
  Line   widget_block.module                                      
 ------ --------------------------------------------------------- 
  146    PHPDoc tag @param references unknown parameter: $forced  
 ------ --------------------------------------------------------- 

 [ERROR] Found 9 errors             
gugalamaciek’s picture

StatusFileSize
new149.92 KB
new5.5 KB

I found two more deprecations:

Deprecations

Patch updated

bramdriesen’s picture

The drush command still needs to be refactored (#7)

saidatom made their first commit to this issue’s fork.

saidatom’s picture

Assigned: Unassigned » saidatom
Status: Needs work » Active

saidatom’s picture

Assigned: saidatom » Unassigned
Status: Active » Needs review
bramdriesen’s picture

Status: Needs review » Reviewed & tested by the community

Some things could be cleaned up with dependency injection, but those should not be a show stopper to get this merged!

stefaniev’s picture

The patch applies, but after updating to Drupal 9.0, I get the following error when using Drush to clear the cache:
The service "widget_block.lazy_builder" has a dependency on a non-existent service "entity.manager".

bramdriesen’s picture

Did you try the patch from #10 or the patch based on the pull request of #14 (https://git.drupalcode.org/project/widget_block/-/merge_requests/3.patch) ?

gugalamaciek’s picture

StatusFileSize
new5.94 KB

@StefanieV please try #19 :) I forgot to change entity.manager to entity_type.manager in widget_block.services.yml

stefaniev’s picture

@BramDriesen, I tried the patch from #10.
@gugalamaciek, great, thanks, the patch from #19 works!
Thanks for all the effort!

økse’s picture

I rerolled the patch against 8.x-1.3-rc1.