php drupal-check.phar modules/contrib/autosave_form/
 22/22 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 ------ ------------------------------------------------------------------------------------ 
  Line   tests/src/FunctionalJavascript/ContentEntity/ContentEntityAutosaveFormTestBase.php  
 ------ ------------------------------------------------------------------------------------ 
  694    Call to deprecated function entity_get_form_display().                              
  725    Call to deprecated function entity_get_form_display().                              
 ------ ------------------------------------------------------------------------------------ 

                                                                                                                        
 [ERROR] Found 2 errors

Comments

Sergiu Stici created an issue. See original summary.

sergiu stici’s picture

Status: Active » Needs review
StatusFileSize
new1.62 KB

Here is the patch, please review.

anavarre’s picture

Title: Updated deprecated code » entity_get_form_display() is deprecated and should be removed
Status: Needs review » Reviewed & tested by the community

Looks good, thank you.

effulgentsia’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/tests/src/FunctionalJavascript/ContentEntity/ContentEntityAutosaveFormTestBase.php
@@ -691,7 +692,7 @@ abstract class ContentEntityAutosaveFormTestBase extends AutosaveFormTestBase {
-      entity_get_form_display($this->entityType, $this->bundle, 'default')
+      EntityFormDisplay::load($this->entityType . '.' . $this->bundle . '.default')

This assumes that the form display already exists. I think the reason #2 passed tests is that the only entity type being tested is Node, and the test setup's drupalCreateContentType() calls node_add_body_field(), which has the side effect of creating and saving a form display. I'm not sure that would be the case if this test is subclassed by something that tests a different entity type.

https://www.drupal.org/node/2835616 says to use \Drupal::service('entity_display.repository')->getFormDisplay() instead, which creates a new display entity if it doesn't already exist. However, that's an API that's only available in Drupal 8.8, and this module might still want to be working with Drupal 8.7.

hchonov’s picture

@effulgentsia, thank you! This is something I wanted to check, but unfortunately I just forgot. I apologize for the delay.

And yes, I would prefer supporting as many Drupal versions as possible. It might not be a clean code, but maybe we could check whether the 8.7 method exists and if not fallback to the old one?

effulgentsia’s picture

StatusFileSize
new2.76 KB

Like this?

  • hchonov committed 92c53cf on 8.x-1.x
    Issue #3086690 by Sergiu Stici, effulgentsia: entity_get_form_display()...
hchonov’s picture

Status: Needs review » Fixed

Exactly, thank you!

Committed and pushed to 8.x-1.x.

milindk’s picture

Verified on latest 8.8.0 release.

autosave_form git:(8.x-1.x) ../../../../vendor/bin/drupal-check -d .
 22/22 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

                                                                                                                        
 [OK] No errors

Status: Fixed » Closed (fixed)

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