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.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | focal_point_for_php84.patch | 1.23 KB | wendyz |
Issue fork focal_point-3593676
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
Comment #2
ruslan piskarovComment #4
recrit commented@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...
Comment #5
wendyz commentedThere 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.
Comment #6
csakiistvanEnvironment
Blocked: not reproducible on 2.1.2
The issue and both attached patches change the constructor of
FocalPointImageWidget, turningImageFactory $image_factory = NULLinto?ImageFactory $image_factory = NULL(and reordering parameters). However, in the targeted release 2.1.2 the classsrc/Plugin/Field/FieldWidget/FocalPointImageWidget.phphas no constructor at all: it no longer injectsImageFactoryorFocalPointManagerInterface, 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
= NULLdefault and no?) exists anywhere.FocalPointPreviewControllerand theimage_focal_pointwidget 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.
Comment #7
jennypanighetti commentedThe error I'm seeing is different from OP; same error, different file.
Comment #9
achapFixed in another issue.