PHP 8.4 deprecates implicitly nullable parameters (a typed parameter with a default value of NULL without an explicit ? nullable type). This causes the following deprecation notice on every page load:

Deprecated: Drupal\focal_point\Plugin\Field\FieldWidget\FocalPointImageWidget::__construct():
Implicitly marking parameter $image_factory as nullable is deprecated,
the explicit nullable type must be used instead in
focal_point/src/Plugin/Field/FieldWidget/FocalPointImageWidget.php on line 42

Fix: Change the $image_factory parameter type hint from ImageFactory to ?ImageFactory in FocalPointImageWidget::__construct().

// Before
ImageFactory $image_factory = NULL,

// After
?ImageFactory $image_factory = NULL,

Steps to reproduce: Install the module on a site running PHP 8.4 and visit any page that uses the focal point image widget.

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:

  • 2.x Comparecompare
  • 3593676-fix-implicit-nullable Comparecompare

Comments

ruslan piskarov created an issue. See original summary.

ruslan piskarov’s picture

Status: Active » Needs review
StatusFileSize
new579 bytes

bleen made their first commit to this issue’s fork.

recrit’s picture

@ruslan piskarov - The FocalPointImageWidget does not have a `__construct()` so the patch provided is a little confusing. Do you have a custom patch applied to the module?

See 2.1.2 file at https://git.drupalcode.org/project/focal_point/-/blob/2.1.2/src/Plugin/F...

wendyz’s picture

StatusFileSize
new1.23 KB

There is another php8.4 warning for this file, which is:
Drupal\focal_point\Plugin\Field\FieldWidget\FocalPointImageWidget::__construct(): Optional parameter $image_factory declared before required parameter
So added the patch file to fix both the implicitly nullable parameter warning and the optional parameter declared before required parameter warning.

csakiistvan’s picture

Status: Needs review » Needs work

Environment

  • Drupal: 11.4.4
  • PHP: 8.5.5
  • Database: MariaDB 10.11.18
  • DDEV: 1.25.2
  • Focal Point: 2.1.2 (the version targeted by the issue)

Blocked: not reproducible on 2.1.2

The issue and both attached patches change the constructor of FocalPointImageWidget, turning ImageFactory $image_factory = NULL into ?ImageFactory $image_factory = NULL (and reordering parameters). However, in the targeted release 2.1.2 the class src/Plugin/Field/FieldWidget/FocalPointImageWidget.php has no constructor at all: it no longer injects ImageFactory or FocalPointManagerInterface, so the parameter the patch targets does not exist. The patches apply to an older widget structure, which is what the reviewer flagged in comment #16632370.

Verification performed

  • Installed and enabled Focal Point 2.1.2 (with Crop API 2.6.0) on PHP 8.5.
  • Static scan of the whole module (non-test PHP): no implicitly nullable typed parameter (a typed parameter with a = NULL default and no ?) exists anywhere.
  • Runtime check: instantiating FocalPointPreviewController and the image_focal_point widget through the container produced 0 "implicitly marking parameter … as nullable" deprecations.

Conclusion

On a clean 2.1.2 the described PHP 8.4/8.5 implicit-nullable deprecation does not occur, because the constructor that the patch modifies was already removed from the widget. The fix cannot be verified against 2.1.2 as written; the patch should be re-based against the actual current widget code (which no longer has that constructor), or the reporter's environment likely runs a customized/older Focal Point where the DI constructor still exists.


Testing produced with the assistance of an LLM.

jennypanighetti’s picture

The error I'm seeing is different from OP; same error, different file.

FILE: /var/www/html/web/modules/contrib/focal_point/tests/src/Unit/FocalPointUnitTestCase.php
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 70 | WARNING | Implicitly marking a parameter as nullable is deprecated since PHP 8.4. Update the type to be explicitly nullable instead. Found implicitly nullable
    |         | parameter: $original_image.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

achap made their first commit to this issue’s fork.

achap’s picture

Status: Needs work » Closed (duplicate)
Related issues: +#3513518: Fix PHP 8.4 deprecation

Fixed in another issue.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.