Problem/Motivation

When updating to D11.2.x or D11.x branch, the Field Validation module fails. This can also be seen when running Drupal CI with the Field Validation module as an dependency as we do in AI module.

This seems to be due to Drupal updating the symfony validator library: https://git.drupalcode.org/project/drupal/-/blob/11.x/composer/Metapacka...

There are property types and output types that has to be defined. As far as I can see they are backwards compatible as well.

Steps to reproduce

  • Add all needed types and return types.

Proposed resolution

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

marcus_johansson created an issue. See original summary.

marcus_johansson’s picture

Assigned: Unassigned » marcus_johansson

marcus_johansson’s picture

Status: Active » Needs review
marcus_johansson’s picture

Assigned: marcus_johansson » Unassigned
scott_euser’s picture

Status: Needs review » Reviewed & tested by the community

This looks good to me. I think given 3x is beta, release notes should just make it clear in case anyone is extending any constraints, that they should add the return types + types to their messages in order to remain compatible.

E.g.

class Class1 {
	public string $message = 'Great message.';
}

class Class2 extends Class1 {
	public $message = 'Great message.';
}
$class = new Class2();

Will result in

Fatal error: Type of Class2::$message must be string (as in class Class1)

And

class Class1 {
	public function myFunction(): string {
		return 'hello1';
	}
}

class Class2 extends Class1 {
	public function myFunction() {
		return 'hello2';
	}
}
$class = new Class2();
print $class->myFunction();

Will result in

Fatal error: Declaration of Class2::myFunction() must be compatible with Class1::myFunction(): string

vivek panicker’s picture

Patch worked for me as well.
Was able to run update hooks successfully.

pearls’s picture

Here's the log while upgrading to Drupal 11.2.0.rc2

  Unable to decode output into JSON: Syntax error                                              
                                                                                               
  Fatal error: Declaration of Drupal\field_validation\Plugin\Validation\Constraint\JsonConstr  
  aint::validatedBy() must be compatible with Symfony\Component\Validator\Constraint::validat  
  edBy(): string in /var/www/html/d11site/web/modules/contrib/field_validation/src/Plugin/Valid  
  ation/Constraint/JsonConstraint.php on line 21  

MR !15 solved the problem.
+1 for RTBC

jrockowitz’s picture

StatusFileSize
new14.75 KB
digitalcatalyst’s picture

tested this patch when upgrading, from core 11.1.7 to 11.2.0, updates were failing with

PHP Fatal error: Declaration of Drupal\field_validation\Plugin\Validation\Constraint\TimeConstraint::validatedBy() must be compatible with Symfony\Component\Validator\Constraint::validatedBy(): string in /var/www/sites/drupal/multisite/web/modules/contrib/field_validation/src/Plugin/Validation/Constraint/TimeConstraint.php on line 21

after patch updates all ran fine.

seattlehimay’s picture

Tested patch from #9 while upgrading from d10 to D11.2.2. This patched worked great, and eliminated the error I had been seeing upon trying update the database via drush:

Fatal error: Type of Drupal\field_validation\Plugin\Validation\Constraint\LessThanOrEqualConstraint::$message must
be string (as in class Symfony\Component\Validator\Constraints\LessThanOrEqual) in /var/www/html/web/modules/contri
b/field_validation/src/Plugin/Validation/Constraint/LessThanOrEqualConstraint.php on line 16

anybody’s picture

Priority: Normal » Major

Definitely major, this breaks projects and updates. Any chance to tag a new release?

doxigo’s picture

This works as expected, and this is a major blocker, can anyone tag a new release please?

abhisekmazumdar’s picture

Status: Reviewed & tested by the community » Fixed

Thank you all for moving this forward. I have created a new release: field_validation 3.0.0-beta5.

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

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

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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

darren oh’s picture

Issue tags: +Drupal Forge, +Vienna2025
darren oh’s picture

Issue tags: -Drupal Forge, -Vienna2025