Closed (fixed)
Project:
Drupal core
Version:
10.3.x-dev
Component:
base system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
13 Feb 2024 at 03:14 UTC
Updated:
17 Mar 2024 at 14:54 UTC
Jump to comment: Most recent
Comments
Comment #4
godotislateI was implementing a custom validation constraint and noticed that Constraint plugins hadn't yet been converted to attributes, so I picked this up. I underestimated level of effort by quite a bit, first in the number of plugins there are, and second the Symfony deprecation notices. Anyway, tests are green, so I assume I caught everything.
Comment #5
godotislateDecided I didn't like aliasing
Drupal\Core\Validation\Attribute\Constraint as ConstraintAttribute, so switched to aliasingSymfony\Component\Validator\Constraint as SymfonyConstraint.Comment #6
smustgrave commentedOnly did a partial review but tagged a few out of scope changes.
Comment #7
godotislateMethod return typehints were added to address tests failing for Symfony deprecations, so not OOS.
Comment #8
smustgrave commentedGotcha,
Then in that case searched for @Constraint and all instances appear to be replaced.
Comment #9
longwaveTo backport this to 10.3.x I am not sure we can add the return types, we might have to add them to the baseline or ignore them instead.
Comment #10
godotislateNot sure if this suggests whether more typehints can be backported, but there are existing typehints on some constraint plugins: Drupal\Core\Entity\Plugin\Validation\Constraint\BundleConstraint
Drupal\Core\Plugin\Plugin\Validation\Constraint\PluginExistsConstraint
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraint.php?ref_type=heads#L51
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/BundleConstraint.php?ref_type=heads#L58
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...
Comment #11
smustgrave commentedCould it be a 11.x only?
Comment #12
godotislateThe alternate approach could be to do something like this:
Comment #13
alexpottWhy is this issue fixing deprecations as well. I feel this should only be doing the attribute conversion. The rest of the changes belong in a separate issue. - no?
Comment #14
godotislate@alexpott - Tests were failing without fixing the typehints and overridden properties. https://git.drupalcode.org/issue/drupal-3420990/-/jobs/893451
Comment #15
godotislateShould the deprecations be taken care of in a separate issue and then block this issue on the deprecations one?
Similar issues: #3233482: [Symfony 6] Add type hints to methods overriding Symfony\Component\Validator\Constraint::getDefaultOption() and ::getRequiredOptions(), #3276196: The "Symfony\Component\Validator\Constraints\Range::$minMessage" property is considered final
Comment #16
alexpott@godotislate why are we suddenly hitting this when we move to attributes? This is already the case. My guess is the conversion is breaking how we are already skipping it so we should fix that here.
Comment #17
godotislate@alexpott I ran the failing test locally, and the issue is that
AttributeClassDiscoveryinstantiates a\ReflectionClasswhen getting definitions, at which point the SymfonyDebugClassLoaderis flagging the deprecations.AnnotatedClassDiscoverydoes not instantiate\ReflectionClass, so that's apparently why it hasn't come up before now.Stack trace
Should we suppress the deprecation messages in
.deprecation-ignore.txt?Comment #18
alexpottYes let's suppress and use documentation - i.e add @return where we can. This is another good thing about attributes - they get checked better by our tools.
Comment #19
godotislateAdded @return as needed and suppressed other deprecation warnings and tests are passing again.
Follow up here: #3425150: Symfony deprecations in Constraint plugins
Comment #20
kim.pepperNW for a couple of minor nitpicks.
Comment #21
kim.pepperWe also need to update https://git.drupalcode.org/project/drupal/-/blob/11.x/core/core.api.php?... to replace
@see \Drupal\Core\Validation\Annotation\Constraintwith@see \Drupal\Core\Validation\Attribute\ConstraintComment #22
kim.pepperSearched for usages of
@Constraintannotation and found none. All feedback addressed. (Are you able to resolve the comment threads?)Comment #23
alexpott@godotislate nice work and creating the follow-up #3425150: Symfony deprecations in Constraint plugins super nice!
Committed and pushed 045dfe1b96 to 11.x and b2971f464b to 10.3.x. Thanks!