4 fixable issues https://dev.acquia.com/drupal9/deprecation_status/errors?project=crop%201.5

Call to deprecated function drupal_set_message(). Deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use Drupal​\​Core​\​Messenger​\​MessengerInterface::addMessage() instead.

Call to deprecated method link() of class Drupal​\​Core​\​Config​\​Entity​\​ConfigEntityBase. Deprecated in Drupal 8.0.0, intended to be removed in Drupal 9.0.0 Use Drupal​\​Core​\​EntityInterface::toLink()->toString() instead.

Comments

jfussion created an issue. See original summary.

jfussion’s picture

Issue tags: +DrupalSouth 2019
milindk’s picture

On 8.x-2.x branch: I can see following deprecations:

➜  d9_ready vendor/bin/drupal-check web/modules/contrib/crop 
 29/29 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 ------ -------------------------------------------------------------------------- 
  Line   crop.install                                                              
 ------ -------------------------------------------------------------------------- 
  24     Call to deprecated function system_get_info():                            
         in drupal:8.8.0 and is removed from drupal:9.0.0. Use                     
         \Drupal::service('extension.list.$type')->getExtensionInfo() or           
         \Drupal::service('extension.list.$type')->getAllInstalledInfo() instead.  
 ------ -------------------------------------------------------------------------- 

                                                                                                                        
 [ERROR] Found 1 error  
After applying patch:

➜  crop git:(8.x-2.x) ✗ ../../../../vendor/bin/drupal-check .
 29/29 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

                                                                                                                        
 [OK] No errors                                                                                                         
 
milindk’s picture

StatusFileSize
new6.28 KB

On 8.x-1.x branch: I can see following deprecations:

➜  crop git:(8.x-1.x) ✗ ../../../../vendor/bin/drupal-check .                    
 29/29 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 ------ --------------------------------------------------------------------------------------- 
  Line   src/CropTypeListBuilder.php                                                            
 ------ --------------------------------------------------------------------------------------- 
  105    Call to deprecated method link() of class Drupal\Core\Config\Entity\ConfigEntityBase:  
         in drupal:8.0.0 and is removed from drupal:9.0.0.                                      
         Use \Drupal\Core\EntityInterface::toLink()->toString() instead.                        
 ------ --------------------------------------------------------------------------------------- 

 ------ ---------------------------------------------------------------------- 
  Line   src/Form/CropTypeDeleteForm.php                                       
 ------ ---------------------------------------------------------------------- 
  102    Call to deprecated function drupal_set_message():                     
         in drupal:8.5.0 and is removed from drupal:9.0.0.                     
         Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead.  
 ------ ---------------------------------------------------------------------- 

 ------ ---------------------------------------------------------------------- 
  Line   src/Form/CropTypeForm.php                                             
 ------ ---------------------------------------------------------------------- 
  174    Call to deprecated function drupal_set_message():                     
         in drupal:8.5.0 and is removed from drupal:9.0.0.                     
         Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead.  
  177    Call to deprecated function drupal_set_message():                     
         in drupal:8.5.0 and is removed from drupal:9.0.0.                     
         Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead.  
 ------ ---------------------------------------------------------------------- 

 ------ ---------------------------------------------------- 
  Line   tests/src/Functional/CropFunctionalTest.php         
 ------ ---------------------------------------------------- 
  159    Call to deprecated function file_unmanaged_copy():  
         in drupal:8.7.0 and is removed from drupal:9.0.0.   
         Use \Drupal\Core\File\FileSystemInterface::copy().  
 ------ ---------------------------------------------------- 

 ------ ---------------------------------------------------- 
  Line   tests/src/Kernel/CropUnitTestBase.php               
 ------ ---------------------------------------------------- 
  116    Call to deprecated function file_unmanaged_copy():  
         in drupal:8.7.0 and is removed from drupal:9.0.0.   
         Use \Drupal\Core\File\FileSystemInterface::copy().  
 ------ ---------------------------------------------------- 

                                                                                                                        
 [ERROR] Found 6 errors         

After applying patch:

➜  crop git:(8.x-1.x) ✗ ../../../../vendor/bin/drupal-check .
 29/29 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

                                                                                                                        
 [OK] No errors                                                                                                         
 
milindk’s picture

Status: Active » Needs review
milindk’s picture

StatusFileSize
new6.34 KB

Fixed code changes and test cases for 8.x-1.x.

amitgoyal’s picture

Status: Needs review » Needs work
Parent issue: » #3071865: [META] Prepare Lightning for Drupal 9

@milindk This issue is meant for 8.x-2.x-dev. I think we should fix deprecations in latest dev-x version if any.

I am not able to patch in #6 on latest 8.x-2.x-dev.

➜  crop git:(8.x-2.x) ✗ git apply -v 3096959-6-d9-deprecated-code-report.patch
Checking patch src/CropTypeListBuilder.php...
error: while searching for:
    $usage = [];
    foreach ($image_styles as $image_style) {
      if (count($usage) < 2) {
        $usage[] = $image_style->link();
      }
    }


error: patch failed: src/CropTypeListBuilder.php:102
error: src/CropTypeListBuilder.php: patch does not apply
Checking patch src/Form/CropTypeDeleteForm.php...
error: while searching for:
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->entity->delete();
    $t_args = ['%name' => $this->entity->label()];
    drupal_set_message($this->t('The crop type %name has been deleted.', $t_args));
    $this->logger('crop')->notice('Deleted crop type %name.', $t_args);

    $form_state->setRedirectUrl($this->getCancelUrl());

error: patch failed: src/Form/CropTypeDeleteForm.php:99
error: src/Form/CropTypeDeleteForm.php: patch does not apply
Checking patch src/Form/CropTypeForm.php...
error: while searching for:
    $t_args = ['%name' => $type->label()];

    if ($status == SAVED_UPDATED) {
      drupal_set_message($this->t('The crop type %name has been updated.', $t_args));
    }
    elseif ($status == SAVED_NEW) {
      drupal_set_message($this->t('The crop type %name has been added.', $t_args));
      $context = array_merge($t_args, ['link' => Link::createFromRoute($this->t('View'), 'crop.overview_types')->toString()]);
      $this->logger('crop')->notice('Added crop type %name.', $context);
    }

error: patch failed: src/Form/CropTypeForm.php:171
error: src/Form/CropTypeForm.php: patch does not apply
Checking patch tests/src/Functional/CropFunctionalTest.php...
error: while searching for:
   */
  protected function doTestFileUriAlter() {
    // Get the test file.
    file_unmanaged_copy(drupal_get_path('module', 'crop') . '/tests/files/sarajevo.png', PublicStream::basePath());
    $file_uri = 'public://sarajevo.png';
    $file = File::create(['uri' => $file_uri, 'status' => FILE_STATUS_PERMANENT]);
    $file->save();

error: patch failed: tests/src/Functional/CropFunctionalTest.php:156
error: tests/src/Functional/CropFunctionalTest.php: patch does not apply
Checking patch tests/src/Kernel/CropUnitTestBase.php...
error: while searching for:
   *   File object.
   */
  protected function getTestFile() {
    file_unmanaged_copy(drupal_get_path('module', 'crop') . '/tests/files/sarajevo.png', PublicStream::basePath());
    return $this->fileStorage->create([
      'uri' => 'public://sarajevo.png',
      'status' => FILE_STATUS_PERMANENT,

error: patch failed: tests/src/Kernel/CropUnitTestBase.php:113
error: tests/src/Kernel/CropUnitTestBase.php: patch does not apply
amitgoyal’s picture

Status: Needs work » Reviewed & tested by the community

#3 looks good to me for 8.x-2.x-dev

➜  d9 git:(8.8.x) ✗ ./vendor/mglaman/drupal-check/drupal-check --drupal-root=./ modules/contrib/crop

 29/29 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%


 [OK] No errors


effulgentsia’s picture

Reuploading #3 for clarity. It looks like the correct fix to me. Even though system_get_info() didn't get deprecated until 8.8.0, ExtensionList::getExtensionInfo() has been around for a while, so I don't think this fix breaks 8.7.

chr.fritsch’s picture

Status: Reviewed & tested by the community » Needs work

This should also be fixed:

Line   test-dir/docroot/modules/contrib/crop/src/CropTypeListBuilder.php  
 ------ ------------------------------------------------------------------- 
  48     Parameter $query_factory of method                                 
         Drupal\crop\CropTypeListBuilder::__construct() has typehint with   
         deprecated class Drupal\Core\Entity\Query\QueryFactory:            
         in drupal:8.3.0 and is removed from drupal:9.0.0. Use              
         \Drupal\Core\Entity\EntityStorageInterface::getQuery() or          
         \Drupal\Core\Entity\EntityStorageInterface::getAggregateQuery()    
         instead.                                                           
 ------ ------------------------------------------------------------------- 
 ------ ----------------------------------------------------------------------- 
  Line   test-dir/docroot/modules/contrib/crop/src/Form/CropTypeDeleteForm.php  
 ------ ----------------------------------------------------------------------- 
  39     Parameter $query_factory of method                                     
         Drupal\crop\Form\CropTypeDeleteForm::__construct() has typehint with   
         deprecated class Drupal\Core\Entity\Query\QueryFactory:                
         in drupal:8.3.0 and is removed from drupal:9.0.0. Use                  
         \Drupal\Core\Entity\EntityStorageInterface::getQuery() or              
         \Drupal\Core\Entity\EntityStorageInterface::getAggregateQuery()        
         instead.                                                               
andreyjan’s picture

Status: Needs work » Needs review
StatusFileSize
new6.94 KB
new7.44 KB

Added changes per #10 and also replaced usages of deprecated 'entity.manager' .

amitgoyal’s picture

Status: Needs review » Reviewed & tested by the community

#11 looks good to me.

➜  d9 git:(8.8.x) ✗ ./vendor/mglaman/drupal-check/drupal-check --drupal-root=./ modules/contrib/crop

 29/29 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%


 [OK] No errors


berdir’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Drupal 9 compatibility
  1. +++ b/src/Form/CropTypeDeleteForm.php
    @@ -31,13 +31,13 @@ class CropTypeDeleteForm extends EntityConfirmFormBase {
        *   The string translation manager.
        */
    -  public function __construct(QueryFactory $query_factory, TranslationInterface $string_translation) {
    -    $this->queryFactory = $query_factory;
    +  public function __construct(EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation) {
    +    $this->storage = $entity_type_manager->getStorage('crop');
         $this->translation = $string_translation;
    

    This is an entity form, which already has entityTypeManager injected through a setter method, so you can just use $this->entityTypeManager->getStorage where it is needed and skip the injection.

  2. +++ b/tests/src/Kernel/CropEntityProvidersTest.php
    @@ -24,8 +24,8 @@ class CropEntityProvidersTest extends CropUnitTestBase {
     
    -    $this->container->get('entity.manager')
    -      ->onEntityTypeCreate($this->container->get('entity.manager')->getDefinition('file'));
    +    $this->container->get('entity_type.listener')
    +      ->onEntityTypeCreate($this->container->get('entity_type.manager')->getDefinition('file'));
       }
     
    

    this should really use installEntityType, also the parent already does this for file anyway, so we can remove setUp() completely IMHO.

Also, lets update info.yml, add a core_version_requirement key instead of core: 8.x per https://www.drupal.org/node/3070687. And a drupal/core requirement to composer.json.

akashkumar07’s picture

Status: Needs work » Needs review
StatusFileSize
new7.75 KB
new3.25 KB

Made suggested changes. Please review.

berdir’s picture

Status: Needs review » Needs work

Thanks, good improvements, still a chunk of things left to do.

drupal-check:

 ------ --------------------------------------------------------------------------------------- 
  Line   src/CropTypeListBuilder.php                                                            
 ------ --------------------------------------------------------------------------------------- 
  105    Call to deprecated method link() of class Drupal\Core\Config\Entity\ConfigEntityBase:  
         in drupal:8.0.0 and is removed from drupal:9.0.0.                                      
         Use \Drupal\Core\EntityInterface::toLink()->toString() instead.                        
 ------ --------------------------------------------------------------------------------------- 

 ------ ---------------------------------------------------------------------- 
  Line   src/Form/CropTypeDeleteForm.php                                       
 ------ ---------------------------------------------------------------------- 
  91     Call to deprecated function drupal_set_message():                     
         in drupal:8.5.0 and is removed from drupal:9.0.0.                     
         Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead.  
 ------ ---------------------------------------------------------------------- 

 ------ ---------------------------------------------------------------------- 
  Line   src/Form/CropTypeForm.php                                             
 ------ ---------------------------------------------------------------------- 
  174    Call to deprecated function drupal_set_message():                     
         in drupal:8.5.0 and is removed from drupal:9.0.0.                     
         Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead.  
  177    Call to deprecated function drupal_set_message():                     
         in drupal:8.5.0 and is removed from drupal:9.0.0.                     
         Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead.  
 ------ ---------------------------------------------------------------------- 

 ------ ---------------------------------------------------- 
  Line   tests/src/Functional/CropFunctionalTest.php         
 ------ ---------------------------------------------------- 
  159    Call to deprecated function file_unmanaged_copy():  
         in drupal:8.7.0 and is removed from drupal:9.0.0.   
         Use \Drupal\Core\File\FileSystemInterface::copy().  
 ------ ---------------------------------------------------- 

 ------ ---------------------------------------------------- 
  Line   tests/src/Kernel/CropUnitTestBase.php               
 ------ ---------------------------------------------------- 
  116    Call to deprecated function file_unmanaged_copy():  
         in drupal:8.7.0 and is removed from drupal:9.0.0.   
         Use \Drupal\Core\File\FileSystemInterface::copy().  

when running tests:

  7x: Entity type "crop_type" is using config schema as a fallback for a missing `config_export` definition is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. See https://www.drupal.org/node/2949023.
    1x in CropFunctionalTest::testCropTypeCrud from Drupal\Tests\crop\Functional
    1x in CropCRUDTest::testCropTypeSave from Drupal\Tests\crop\Kernel
    1x in CropCRUDTest::testCropSave from Drupal\Tests\crop\Kernel
    1x in CropCRUDTest::testOrphanRemoval from Drupal\Tests\crop\Kernel
    1x in CropEffectTest::testCropEffect from Drupal\Tests\crop\Kernel
    1x in CropEffectTest::testCropDimenssions from Drupal\Tests\crop\Kernel
    1x in CropEntityProvidersTest::testCropEffect from Drupal\Tests\crop\Kernel

  6x: file_unmanaged_copy() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\File\FileSystemInterface::copy(). See https://www.drupal.org/node/3006851.
    1x in CropFunctionalTest::testCropTypeCrud from Drupal\Tests\crop\Functional
    1x in CropCRUDTest::testCropSave from Drupal\Tests\crop\Kernel
    1x in CropCRUDTest::testOrphanRemoval from Drupal\Tests\crop\Kernel
    1x in CropEffectTest::testCropEffect from Drupal\Tests\crop\Kernel
    1x in CropEffectTest::testCropDimenssions from Drupal\Tests\crop\Kernel
    1x in CropEntityProvidersTest::testCropEffect from Drupal\Tests\crop\Kernel

  3x: FileSystem::uriScheme() is deprecated in drupal:8.8.0. It will be removed from drupal:9.0.0. Use \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface::getScheme() instead. See https://www.drupal.org/node/3035273
    3x in CropFunctionalTest::testCropTypeCrud from Drupal\Tests\crop\Functional

  2x: drupal_set_message() is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead. See https://www.drupal.org/node/2774931
    2x in CropFunctionalTest::testCropTypeCrud from Drupal\Tests\crop\Functional

  1x: Drupal\Tests\BrowserTestBase::$defaultTheme is required in drupal:9.0.0 when using an install profile that does not set a default theme. See https://www.drupal.org/node/3083055, which includes recommendations on which theme to use.
    1x in CropFunctionalTest::testCropTypeCrud from Drupal\Tests\crop\Functional

  1x: EntityInterface::link() is deprecated in Drupal 8.0.0 and will be removed in Drupal 9.0.0. Use EntityInterface::toLink()-&gt;toString() instead. Note, the default relationship for configuration entities changes from 'edit-form' to 'canonical'. See https://www.drupal.org/node/2614344
    1x in CropFunctionalTest::testCropTypeCrud from Drupal\Tests\crop\Functional

Mostly overlaps but not completely.

The crop_type problem has a dedicated issue: #3088355: crop_type config entity requires a config_export key since Drupal 8.7, so lets ignore the. Lets also ignore the few 8.8 only deprecations.

The other things can already be fixed.

phenaproxima’s picture

Status: Needs work » Reviewed & tested by the community

Applied the patch in #14 to 8.x-1.x, then ran drupal-check and all tests locally. Nothing reported any errors. I think this is good to go. I'd like to commit it and roll a release; but I'd like to confirm with another maintainer before I do this.

phenaproxima’s picture

Status: Reviewed & tested by the community » Needs review

Ah wait, I missed the deprecation errors thrown by tests. Those are still present. Investigating more closely...

phenaproxima’s picture

StatusFileSize
new7.72 KB

Okay, back to RTBC. I confirmed that 8.7.x deprecations do not get thrown by tests. This final patch changes the core_version_requirement to the more precise '^8.7.7 || ^9' value, but other than that is identical to #14.

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

And, back to RTBC. D'oh.

phenaproxima’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new7.72 KB

Sigh.

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

Okay, back to RTBC now.

berdir’s picture

+1, forget my previous comment, I was drunk or something. There is only one single 8.8+ deprecation left with this patch now against 8.x-2.x:

3x: FileSystem::uriScheme() is deprecated in drupal:8.8.0. It will be removed from drupal:9.0.0. Use \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface::getScheme() instead. See https://www.drupal.org/node/3035273
    3x in CropFunctionalTest::testCropTypeCrud from Drupal\Tests\crop\Functional

That will need to wait until we require 8.8.

  • phenaproxima committed f9e4894 on 8.x-2.x
    Issue #3096959 by milindk, phenaproxima, andreyjan, AkashkumarOSL,...
phenaproxima’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x-2.x. Thanks!

effulgentsia’s picture

Awesome to see the 2.x branch fixed!

Is #22 an accurate comment? If I remove the crop.install hunk from #20 and apply the rest of that patch to 1.x, I still get 6 deprecation errors, but not the one related to uriScheme() mentioned in #22.

Not sure if we care about supporting 1.x on Drupal 9, so this question might not be relevant, but posting this comment in case anyone else stumbles on #22 and is confused by it.

berdir’s picture

No, I meant 8.x-2.x in #22.

The 1.x branch is for media_entity compatibility, which currently does intend to become D9 compatible. A lot of existing installs might still use that branch as they don't use media at all, so updating should be easy, now that is the stable and recommended version. media_entity usage has been going down slowly but steadily as well: https://www.drupal.org/project/usage/media_entity.

effulgentsia’s picture

No, I meant 8.x-2.x in #22.

Ok, great! However, I don't see uriScheme() being called anywhere in the 2.x branch of CropFunctionalTest. Are you still seeing that error?

berdir’s picture

effulgentsia’s picture

Ah, yes, that highlights the limitation of PHPStan (or static analysis in general).

If you change:

$scheme = \Drupal::service('file_system')->uriScheme($uri);

to:

/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::service('file_system');
$scheme = $file_system->uriScheme($uri);

Then, PHPStan will flag it as a deprecation error. But the current top code block does not get flagged as an error in static analysis, so I guess only during runtime testing.

Status: Fixed » Closed (fixed)

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