Problem/Motivation

Follow-up to #3375447: Create an UploadedFile validator and deprecate error checking methods on UploadedFileInterface the \Drupal\Core\TypedData\Validation\ExecutionContextFactory and \Drupal\Core\TypedData\Validation\ExecutionContext can be used by any RecursiveValidator implementation, and have no dependency on TypedData.

Steps to reproduce

Proposed resolution

Move these classes to the \Drupal\Core\Validation namespace and deprecate the old classes and services.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3393099

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

kim.pepper created an issue. See original summary.

kim.pepper’s picture

larowlan’s picture

Title: [PP-1] Move ExecutionContext and ExecutionContextFactory from TypedData to Validation namespace » Move ExecutionContext and ExecutionContextFactory from TypedData to Validation namespace
Status: Postponed » Needs work

Blocker is in

kim.pepper’s picture

Title: Move ExecutionContext and ExecutionContextFactory from TypedData to Validation namespace » Move ExecutionContext, ExecutionContextFactory and ConstraintViolationBuilder from TypedData to Validation namespace
Status: Needs work » Needs review

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Marking as move seems fine.

Only concern is will this immediately break contrib modules? See some existing tests and validations had to be updated. But not sure how to backwards check a move.

kim.pepper’s picture

We are subclassing the exact same code in a new namespace, so existing code should work fine, just trigger the deprecation warning. We could add a deprecation test, but we don't usually do that for constructors.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Added some questions to the MR

kim.pepper’s picture

Status: Needs work » Needs review

Addressed feedback.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

appears all feedback has been addressed.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I asked anothe question on the MR

kim.pepper’s picture

Status: Needs work » Needs review

All threads resolved.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Seems all threads have been resolved again :)

xjm’s picture

Status: Reviewed & tested by the community » Needs work

We have an opportunity while doing this to add parameter and return typehints to everything that's missing them (methods, parameters, etc.). (Normally, changes to moved code might be considered out of scope, but ensuring new API additions are typehinted properly is a higher priority and does not significantly impact the scope since it's only the top level of the moved code.) Once that's done, we can also mention it in the CR.

Thanks!

kim.pepper’s picture

Status: Needs work » Needs review
xjm’s picture

Title: Move ExecutionContext, ExecutionContextFactory and ConstraintViolationBuilder from TypedData to Validation namespace » Move ExecutionContext, ExecutionContextFactory, and ConstraintViolationBuilder from TypedData to Validation namespace
xjm’s picture

xjm’s picture

Some helpful test failures, mostly for strings vs. stringables. (So I guess we either need to allow \Stringable in addition to string basically, or to change existing usages to typecast.)

I belatedly realized there might be some limitations in method typehinting based on the interface, but at least the constructors and member properties should be fair game for the typehint additions.

xjm’s picture

Status: Needs review » Needs work
kim.pepper’s picture

Not sure what is causing the AdminUI Javascript test fails. 😒

kim.pepper’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record updates

I missed the string type errors in the kernel tests earlier. Finally found them!

I've added a deprecation trigger for \Drupal\Core\Validation\ConstraintViolationBuilder::atPath($path) because there were a couple of places passing int and the interface specifies string. Added this to the change record.

We are passing string, \Stringable, and int to \Drupal\Core\Validation\ConstraintViolationBuilder::setParameter(string $key, mixed $value). Not sure whether we should try and reduce that down to just string and \Stringable?

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Move still seems fine

longwave’s picture

Status: Reviewed & tested by the community » Needs work
Related issues: +#3407159: [11.x] Add void returns for Symfony 7

Added some feedback to the MR.

kim.pepper’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Reviewed the change and appears all feedback has been addressed.

Like we added typehints for everything too.

Deprecation appears correct, CR reads well.

LGTM

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Needs a rebase.

kim.pepper’s picture

Status: Needs work » Reviewed & tested by the community

Rebased on 11.x

alexpott’s picture

Version: 11.x-dev » 10.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed eacd1fa and pushed to 11.x. Thanks!
Committed 36f2784 and pushed to 10.3.x. Thanks!

diff --git a/core/lib/Drupal/Core/Validation/ExecutionContext.php b/core/lib/Drupal/Core/Validation/ExecutionContext.php
index ad732ea9f9..5fdf1e6e52 100644
--- a/core/lib/Drupal/Core/Validation/ExecutionContext.php
+++ b/core/lib/Drupal/Core/Validation/ExecutionContext.php
@@ -110,8 +110,12 @@ public function setConstraint(Constraint $constraint): void {
 
   /**
    * {@inheritdoc}
+   *
+   * phpcs:ignore Drupal.Commenting.FunctionComment.VoidReturn
+   *
+   * @return void
    */
-  public function addViolation(string $message, array $params = []): void {
+  public function addViolation(string $message, array $params = []) {
     $this->violations->add(new ConstraintViolation($this->translator->trans($message, $params, $this->translationDomain), $message, $params, $this->root, $this->propertyPath, $this->value, NULL, NULL, $this->constraint));
   }
 

Added the above code back to the 10.3.x backport so we didn't change return types.

  • alexpott committed 36f2784c on 10.3.x
    Issue #3393099 by kim.pepper, smustgrave, xjm, alexpott, longwave: Move...

  • alexpott committed eacd1fa3 on 11.x
    Issue #3393099 by kim.pepper, smustgrave, xjm, alexpott, longwave: Move...

Status: Fixed » Closed (fixed)

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