Problem/Motivation

AFAICT we're replacing our
protected $supportedInterfaceOrClass

with Symfony's public function getSupportedTypes(?string $format): array.
If that is the case can/should we try to deprecate our class property $supportedInterfaceOrClass?

From #3338328-24: Update to Symfony 6.3
Details https://symfony.com/blog/new-in-symfony-6-3-performance-improvements#imp...

Proposed resolution

- remove property definition in core and throw deprecation message
- add a deprecation test and make sure all normalizers are fixed

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3360124

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

catch created an issue. See original summary.

elber made their first commit to this issue’s fork.

elber’s picture

Status: Active » Needs review
andypost’s picture

Status: Needs review » Needs work
Issue tags: +Needs change record
StatusFileSize
new20.84 KB

I bet it needs to convert and clean-up all usages in core

here's a different approach - removal of property definition and throwing deprecation message

andypost’s picture

It could use existing change record https://www.drupal.org/node/3359695 as the method now more useful

But maybe it should use parent method implementation (from Symfony)

andypost’s picture

StatusFileSize
new1.34 KB
new21.55 KB

fix cs

andypost’s picture

Issue summary: View changes

Updated IS a bit

andypost’s picture

StatusFileSize
new5.54 KB
new23.93 KB

Fix few tests

andypost’s picture

StatusFileSize
new886 bytes
new23.84 KB

fix cs

andypost’s picture

Issue summary: View changes
andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new5.89 KB
new28.58 KB

Fix last tests

elber’s picture

Status: Needs review » Reviewed & tested by the community

Hi applied succesfully in drupal 11.x version
Tests are passing
Deprecations are corrects (deprecation message follows the required patters)
Property has been removed has issue's summary says

Moving to RTBC

catch’s picture

Committed/pushed to 11.x, thanks!

I thought about backporting this to 10.1.x but I don't think the late deprecation after beta will particularly help anyone.

spokje’s picture

Not seeing the push yet?

Also unsure if this needs a change record as per the tag?

  • catch committed a50411ad on 11.x
    Issue #3360124 by andypost, elber: Deprecate ::supportedInterfaceOrClass...
catch’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs change record

I've added this issue to https://www.drupal.org/node/3359695 but I don't think we need a separate one.

andypost’s picture

I think it needs follow-up to remove other mentions in code-comments

spokje’s picture

wim leers’s picture

I was (pleasantly!) surprised to already see this land due to its BC break implications … but I see it landed only in 11.x! 🤯 Will this not be a problem for 10.2!

spokje’s picture

- Deprecation warning is on 10.2 in the 11.x branch
- The 10.2.x branch will be branched from 11.x branch at the time of 10.2.0-alpha1, so that will "inherit"the deprecation.

I think we're good.

catch’s picture

Status: Fixed » Patch (to be ported)

Yes this will be in 10.2. https://www.drupal.org/about/core/blog/new-drupal-core-branching-scheme-...

I do wonder if we should consider backporting this bit (and the similar ones) to 10.1, without the deprecation message, so that contrib modules can start to use it as soon as they drop support for 10.0 and 9.5:

+++ b/core/modules/serialization/src/Normalizer/NormalizerBase.php
@@ -37,7 +30,13 @@ public function supportsNormalization($data, string $format = NULL, array $conte
 
-    $supported = (array) $this->supportedInterfaceOrClass;
+    if (property_exists($this, 'supportedInterfaceOrClass')) {
+      @trigger_error('Defining ' . static::class . '::supportedInterfaceOrClass property is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use getSupportedTypes() instead. See https://www.drupal.org/node/3359695', E_USER_DEPRECATED);
+      $supported = (array) $this->supportedInterfaceOrClass;
+    }
+    else {
+      $supported = array_keys($this->getSupportedTypes($format));
+    }

Moving back to 'to be ported' in case people agree.

andypost’s picture

Version: 11.x-dev » 10.1.x-dev
Status: Patch (to be ported) » Needs review
StatusFileSize
new1.28 KB
new28.09 KB

Here's patch #12 but without deprecation

spokje’s picture

Status: Needs review » Needs work

TestBot is unhappy about the 9.5.x patch :/

andypost’s picture

Status: Needs work » Needs review

The patch is for 10.1 which has SF 6.3 and can benefit from the change, 9.5 I triggered just for fun

spokje’s picture

Thanks @andypost, I was already wondering about SF 6.3 and 9.5.x.

Also, we had a few escapees (See #3360280: Add missing ::hasCacheableSupportsMethod deprecations), may we should get those in first and then do the backport?

Nvm, outdated issue by now.

andypost’s picture

Good idea to combine backport with polishing, we can include #3361401: Remove remaining occurences of ::supportedInterfaceOrClass property

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

So marking as the tests seem green. Change record appears to cover what's happening too.

  • catch committed f3d4f1b7 on 10.1.x
    Issue #3360124 by andypost, elber, catch, Spokje: Deprecate ::...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed f3d4f1b and pushed to 10.1.x. Thanks!

Status: Fixed » Closed (fixed)

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

nicxvan’s picture

I'd like to add some information to the change record. I got hit with a deprecation that referenced the change record associated with this issue.

https://git.drupalcode.org/project/rest_views/-/commit/69d089ef7794badda...

The change record did not seem to address this case. I'd propose updating the title to something like:

Normalizers/Denormalizers should implement ::getSupportedTypes() instead of ::hasCacheableSupportsMethod() or using protected $supportedInterfaceOrClass

Then in the change record showing a before and after:

Before

  /**
   * The interface or class that this Normalizer supports.
   *
   * @var array
   */
  protected $supportedInterfaceOrClass = [RenderableData::class];

After

  /**
   * {@inheritdoc}
   */
  public function getSupportedTypes(?string $format): array {
    return [
      RenderableData::class => TRUE,
    ];
  }