Problem/Motivation

PHPStan warnings were fixed in #3483115: Fix phpstan warnings. In field formatters create method was new static() replaced with new self(). If I had to guess, there was warning "Unsafe usage of new static()" reported and this was attempt to fix it. This fix made field formatter classes non extendable, since self resolves to field formatter class and not to the class that extends it.

Proposed resolution

Use the $instance = parent::create() pattern instead of implementing __construct().

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

trafo created an issue. See original summary.

trafo’s picture

Status: Active » Needs review

I implemented proposed solution. The same approach is used in Thumbnail field formatter.

mably’s picture

The usage of static doesn't generate PHPStan warnings anymore.

May be we should just switch back to using static instead of the much too restrictive self?

I guess it would be less impactful.

  • mably committed e87663c2 on 3.0.x
    Issue #3518389 by trafo, mably: Make field formatters extendable
    
mably’s picture

Status: Needs review » Fixed

Switched back to static for now.

  • mably committed 71bef858 on 3.x
    Issue #3518389 by trafo, mably: Make field formatters extendable
    

Status: Fixed » Closed (fixed)

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