Problem/Motivation

Spin-off from #2712647: Update Symfony components to ~3.2.

The interface has changed, but in core we don't really call any methods on it. Symfony was generally good for providing forward compatibility between 2.8 and 3.0 but there's no way to write compatible code against both interfaces with this one.

Proposed resolution

Create a new interface that extends from the 2.8 version in 8.1.x and the 3.0 version in 8.2.x, that way modules can be written that work with both versions.

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

catch created an issue. See original summary.

catch’s picture

catch’s picture

klausi’s picture

The downside of this is that the next 8.1.x minor release will introduce the API break where people have to change their validator code, right? So instead of having the API break with the release of 8.2.x we have it with the next 8.1.x release.

But yeah, maybe the compatibility with both branches is worth it.

catch’s picture

The downside of this is that the next 8.1.x minor release will introduce the API break where people have to change their validator code, right?

You'll still be able to use the interface since that won't be removed in 8.1.x, and the new interface we're adding extends the old one so type hints should still be valid. Your module will be broken in 8.2.x until you update still of course, can't do anything about that.

Since I only updated one class in user module, we should find out what exactly breaks once test run finishes.

The last submitted patch, 2: 2746337-8-1-x.patch, failed testing.

The last submitted patch, 2: 2746337.patch, failed testing.

The last submitted patch, 3: 2746337.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 3: 2746337-8-1-x.patch, failed testing.

catch’s picture

Doh. This isn't going to work, or not without a lot more hackery.

Fatal error: Declaration of Drupal\user\Plugin\Validation\Constraint\UserMailRequired::initialize() must be compatible with Symfony\Component\Validator\ConstraintValidatorInterface::initialize(Symfony\Component\Validator\ExecutionContextInterface $context) in /var/www/html/core/modules/user/src/Plugin/Validation/Constraint/UserMailRequired.php on line 21
✗	
nkno

dawehner’s picture

Did we considered to use class_alias() again for the greater good?

klausi’s picture

@dawehner: I didn't know class_alias(), do you have an issue where we discussed it already?

class_alias() sounds a bit magic to me. Where would we put the class_alias() calls? Isn't it very confusing then when reading the code that a namespaced interface is suddenly a different interface with a different namespace? It looks like class_alias() also works with interfaces, so at least there seems to be some technical possibility.

catch’s picture

ditto what klausi said, new to me too and not obvious where to call it.

Isn't it very confusing then when reading the code that a namespaced interface is suddenly a different interface with a different namespace?

It would be, but ideally this code would only have to exist for 6-12 months, so if prevents a hard break between sequential releases, +1 in spite of the weirdness.

dawehner’s picture

One obvious place could be somehow in DrupalKernel

klausi’s picture

Another obvious place would be a custom autoloader like done in https://samsonasik.wordpress.com/2014/12/19/symfony-2-6-1-class_alias-of...

klausi’s picture

Status: Needs work » Needs review
FileSize
581 bytes

Or in autoload.php? Attached is a patch what I have in mind.

This will break on the current 8.2.x branch with Symfony 2 because the new interface already exists. So we will have to do this as part of #2712647: Update Symfony components to ~3.2.

dawehner’s picture

That would work for me. Its ugly but that how BC layers are.

Status: Needs review » Needs work

The last submitted patch, 16: exec-context-2746337-16.patch, failed testing.

jibran’s picture

+++ b/autoload.php
@@ -11,4 +11,11 @@
+// Backwards compatibility: create aliases for interfaces that have been moved
+// in Symfony 3.
+// @todo Remove this in 8.3.x.
+class_alias('Symfony\Component\Validator\Context\ExecutionContextInterface', 'Symfony\Component\Validator\ExecutionContextInterface');

Let's move it to a new file (class_aliases.php) so that we can maintain the list and update it as needed.

klausi’s picture

Status: Needs work » Closed (won't fix)

As posted in #2712647: Update Symfony components to ~3.2 I think we have exhausted our ideas here with no working outcome. Feel free to reopen if you can get something working.