Problem/Motivation

Image Captcha in Drupal 10 beta 1 causes PHP fatal error in CaptchaImageResponse::prepare

PHP Fatal error:  Declaration of Drupal\image_captcha\Response\CaptchaImageResponse::prepare(Symfony\Component\HttpFoundation\Request $request) must be compatible with Symfony\Component\HttpFoundation\Response::prepare(Symfony\Component\HttpFoundation\Request $request): static in /var/www/web/modules/contrib/captcha/image_captcha/src/Response/CaptchaImageResponse.php on line 71

Steps to reproduce

Enable image_captcha and visit admin/config/people/captcha/image_captcha and expand the example.

Issue fork captcha-3314552

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

eporama created an issue. See original summary.

Anybody’s picture

Priority: Normal » Major
Issue tags: +Drupal 10 compatibility

Indeed this is important to fix for Drupal 10!

srijeeta’s picture

Assigned: Unassigned » srijeeta
Anybody’s picture

Assigned: srijeeta » Unassigned

@Grevil: Wondering why no test fails with this error? Is there no test accessing the configuration page and checking its status code? Then that should be added here.

Anybody’s picture

@eporama does the attached MR fix the issue for you?

@Grevil: Beside adding a test that is expected to fail in 8.x-1.x currently, I guess the same fix and test should be added to 2.x?
Also I'm unsure if this might break Drupal 8 / 9 installations.

So my guess would be to

  1. add test for the settings forms in 8.x-1.x and 2.x
  2. remove Drupal 10 support from 8.x-1.x as soon as 2.0 lands (should be added to the appropriate 2.x issue?)
  3. Add and test the fix for 2.x and decide if it can be safely mergend into 8.x-1.x
Anybody’s picture

Anybody’s picture

Assigned: Unassigned » Grevil
Status: Active » Needs review
Grevil’s picture

Status: Needs review » Active

I think, we should only apply these changes in 2.x, as they won't be fully compatible with Drupal 8 / 9 instances using PHP<8.0, as the "Symfony\Component\HttpFoundation\Response" class added loads of return type hinting in their newest release used in D10. This is usually not a big Problem as they can be simply added and even if the parent method doesn't have these return type hints, it won't throw an error.

The big problem is, that the static return type hint is a PHP 8 feature, so if we add the hinting in 8.x, we will make it incompatible with Drupal Sites using

So I am against adding this to 8.x.

Instead, let's apply the changes in 2.x and make the module only compatible with Drupal 10. As it requires at least PHP 8.1.

Grevil’s picture

Version: 8.x-1.x-dev » 2.x-dev
Priority: Major » Normal

Setting this to "Normal", as Drupal 10 has not released yet.

Grevil’s picture

@eporama try this patch. Not sure if it will work, but the MR will definitely not!

Grevil’s picture

@Anybody there aren't any image_captcha tests currently in 2.x nor in 8.x, I will add some basic tests for the module inside #3316486: [2.x] Code review, cleanup and tests!

Grevil’s picture

Also, "sendContent()" originally returned void, but now needs to return "static", so we definitely need to make 2.x Drupal 10 only.

Anybody’s picture

Okay, let's do it that way and document it somewhere. Perhaps even on the module page, linking the corresponding issue for documentation?

Anybody’s picture

Title: CaptchaImageResponse::prepare incompatible in D10 » [2.x] CaptchaImageResponse::prepare incompatible in D10
Grevil’s picture

We should also remove jquery/once here! :)

Anybody’s picture

Anybody’s picture

Priority: Normal » Major

@Grevil: I switched the 2.x tests to D10, so please review and commit this first! :)

Anybody’s picture

Status: Active » Needs review
Anybody’s picture

Title: [2.x] CaptchaImageResponse::prepare incompatible in D10 » [2.x only] CaptchaImageResponse::prepare incompatible in D10

Grevil’s picture

Anybody’s picture

Status: Needs review » Reviewed & tested by the community

LGTM!

Anybody’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for merging :D

Grevil’s picture

Fixed, sorry for the bad commit message!

Status: Fixed » Closed (fixed)

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