Problem/Motivation

Running GrumPHP compatibility test returns 2 errors

php_compatibility
=================

FILE: ...atpickr/src/Plugin/Field/FieldWidget/DateTimeFlatPickrWidget.php
----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------
388 | ERROR | "$this" can no longer be used in a plain function or
| | method since PHP 7.1.
| | (PHPCompatibility.Variables.ForbiddenThisUseContexts.OutsideObjectContext)
410 | ERROR | "$this" can no longer be used in a plain function or
| | method since PHP 7.1.
| | (PHPCompatibility.Variables.ForbiddenThisUseContexts.OutsideObjectContext)

Steps to reproduce

On PHP 8.0 run PHP compatibility test for this module.

Proposed resolution

Replace $this->t with new TranslatableMarkup

Remaining tasks

User interface changes

API changes

Data model changes

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

deiviic created an issue. See original summary.

tmaiochi’s picture

Assigned: Unassigned » tmaiochi

I'll work on this!

tmaiochi’s picture

Assigned: tmaiochi » Unassigned
Status: Active » Needs review

I replaced $this->t with new TranslatableMarkup as proposed resolution, Kindly review it!

deiviic’s picture

I suggested new TranslatableMarkup because that was in the method itself but after reading a little, it seems just t() could be used. Not sure what would be the better option..

avpaderno’s picture

Version: 2.0.1 » 2.0.x-dev
Issue tags: -PHP 8.0 compatibility
avpaderno’s picture

Title: "$this" can no longer be used in a plain function or method since PHP 7.1. » "$this" can no longer be used in a plain function or static method since PHP 7.1
Status: Needs review » Needs work

Since the element validation handler is added with '#element_validate' => [[$this, 'fieldSettingsHourElementValidate'],] it is wrong to define fieldSettingsHourElementValidate() as static method.

nagy.balint’s picture

I'll check, maybe indeed those do not need to be static.

nagy.balint’s picture

Status: Needs work » Needs review
StatusFileSize
new1.15 KB

  • nagy.balint committed 13bb0cc on 2.0.x
    Issue #3272728 by tmaiochi, nagy.balint, deiviic, apaderno: "$this" can...
nagy.balint’s picture

Status: Needs review » Fixed

Thanks!

Status: Fixed » Closed (fixed)

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