When I save a node using the textfield counter, on PHP 8.1, I get this error.

Deprecated function: Calling static trait method Drupal\textfield_counter\Plugin\Field\FieldWidget\TextFieldCounterWidgetTrait::getLengthOfSubmittedValue is deprecated, it should only be called on a class using the trait in Drupal\textfield_counter\Plugin\Field\FieldWidget\TextFieldCounterWidgetTrait::validateFieldFormElement() (line 352 of modules/contrib/textfield_counter/src/Plugin/Field/FieldWidget/TextFieldCounterWidgetTrait.php).

Comments

Daniel Korte created an issue. See original summary.

coaston’s picture

Same issue here, any patch please ?

coaston’s picture

StatusFileSize
new2.19 KB

@Daniel,

I tried to create a patch, but I am not sure if it is ok - it works for me, but still note sure if this is a good approach. Feel free to test.

-issues says that we should not call Calling static trait method from function getLengthOfSubmittedValue, but now it should be called directly from function validateFieldFormElement, so I just moved that code there and removed getLengthOfSubmittedValue function.

qrinaldi’s picture

StatusFileSize
new2.08 KB

Hi
I can't use the #3 patch. Here is mine.

qrinaldi’s picture

avpaderno’s picture

Title: PHP 8.1 Deprecated Function » Calling a static method, or accessing a static property directly on a trait is deprecated
Issue summary: View changes
Issue tags: +PHP 8.1
avpaderno’s picture

Status: Active » Needs review
geoffray’s picture

Patch #4 worked for me. Thanks

godotislate’s picture

StatusFileSize
new5.47 KB

I think the way the validate callback is added can be simplified so that it's called by the class.
Patch attached.

edmund.dunn’s picture

#4 worked for me!

coaston’s picture

#9 works fine.

kris77’s picture

#9 works for me too.
Thanks @coaston

svendecabooter’s picture

Version: 2.0.0 » 2.1.0
Status: Needs review » Reviewed & tested by the community

Patch #9 works as expected. Marking as RTBC

  • godotislate authored ac0c7312 on 2.x
    Issue #3272128 by qrinaldi, godotislate, coaston, apaderno, Daniel Korte...
edmund.dunn’s picture

Status: Reviewed & tested by the community » Fixed
edmund.dunn’s picture

Status: Fixed » Closed (fixed)