Problem/Motivation

In #3093747: Add alias process service back (deprecated) and improve DX around BC path_alias services we deprecated a bunch of services and classes and added them to DeprecationListenerTrait to be able to make as little changes as possible and thus prove the changes were fully BC. However this also prevents contrib maintainers from getting warnings that they are using deprecated functionality.

Proposed resolution

Remove usages of deprecated path alias services and clear DeprecationListenerTrait entries.

Remaining tasks

  • Validate the proposed solution
  • Write a patch
  • Review it

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

None

Comments

plach created an issue. See original summary.

plach’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new35.43 KB
berdir’s picture

  1. +++ b/core/core.api.php
    @@ -761,7 +761,7 @@
      *
      * A typical service definition in a *.services.yml file looks like this:
      * @code
    - * path.alias_manager:
    + * path_alias.manager:
      *   class: Drupal\path_alias\AliasManager
      *   arguments: ['@path.crud', '@path_alias.whitelist', '@language_manager']
    

    this is an arbitrary example but now it's one that is no longer in core.services.yml. In a way, I suppose that's better because such an example is closer to what people looking at that documentation actually want to do ;)

    That said, it has path.crud as an argument, which hasn't existed for, uhm, 6 years :)

  2. +++ b/core/core.services.yml
    @@ -1218,7 +1218,7 @@ services:
       path_subscriber:
         class: Drupal\Core\EventSubscriber\PathSubscriber
    -    arguments: ['@path.alias_manager', '@path.current']
    +    arguments: ['@path_alias.manager', '@path.current']
    

    doesn't really matter if the deprecated service or not, but I guess it is currently identical and would result in fewer (misleading) deprecation messages if you'd only access that.

  3. +++ b/core/modules/path/src/PathAliasListBuilder.php
    @@ -63,7 +63,7 @@ class PathAliasListBuilder extends EntityListBuilder {
        *   The language manager.
    -   * @param \Drupal\Core\Path\AliasManagerInterface $alias_manager
    +   * @param \Drupal\path_alias\AliasManagerInterface $alias_manager
        *   The path alias manager.
    

    this is new in 8.8, so if we can still get it in, I suppose we don't have to worry about BC :)

  4. +++ b/core/modules/system/src/Form/SiteInformationForm.php
    @@ -64,7 +64,7 @@ public function __construct(ConfigFactoryInterface $config_factory, AliasManager
           $container->get('config.factory'),
    -      $container->get('path.alias_manager'),
    +      $container->get('path_alias.manager'),
           $container->get('path.validator'),
    

    Ok, so you're currently only updating the service but not the interface for this form and RequestPath (at least with this one, a subclassed constructor is imaginable.. found one but that doesn't change the constructor: http://grep.xnddx.ru/node/29452542).

    What we could *maybe* still get into 8.8 beta would be removing the type hint checking if it implements the new interface, and if not, then we'd do a @trigger_error?

  5. +++ b/core/modules/views/src/Plugin/views/argument_default/Raw.php
    @@ -64,7 +64,7 @@ public static function create(ContainerInterface $container, array $configuratio
           $plugin_id,
           $plugin_definition,
    -      $container->get('path.alias_manager'),
    +      $container->get('path_alias.manager'),
           $container->get('path.current')
    

    same.

  6. +++ b/core/modules/workspaces/workspaces.services.yml
    @@ -40,7 +40,7 @@ services:
           - { name: 'event_subscriber' }
       workspaces.workspace_subscriber:
         class: Drupal\workspaces\EventSubscriber\WorkspaceRequestSubscriber
    -    arguments: ['@path.alias_manager', '@path.current', '@router.route_provider', '@workspaces.manager']
    +    arguments: ['@path_alias.manager', '@path.current', '@router.route_provider', '@workspaces.manager']
         tags:
    

    workspaces is/was still experimental and this class is new, so we can update the type hint of this class.

  7. +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php
    @@ -67,7 +68,7 @@ public function testContainerWithLazyServices() {
       public function testContainerWithLazyServicesWithoutProxyClass() {
         $container = new ContainerBuilder();
    -    $container->register('alias_whitelist', 'Drupal\Core\Path\AliasWhitelist')
    +    $container->register('alias_whitelist', AliasWhitelist::class)
           ->setLazy(TRUE);
    

    should a test in core/tests rely on a path_alias service or should we use something else for this test? not sure.

plach’s picture

StatusFileSize
new13.85 KB
new47 KB

This addresses #4, I think :)

Status: Needs review » Needs work

The last submitted patch, 5: path-alias_module-3084983-5.patch, failed testing. View results

ravi.shankar’s picture

Status: Needs work » Needs review

Patch #5 has passed the test so I am moving it to needs review.

jibran’s picture

Assigned: plach » Unassigned
Status: Needs review » Reviewed & tested by the community

Patch looks good to me. Can we still backport this to 8.8.x?

berdir’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/system/src/Form/SiteInformationForm.php
@@ -43,16 +44,26 @@ class SiteInformationForm extends ConfigFormBase {
 
+    if (!$alias_manager instanceof AliasManagerInterface) {
+      if ($alias_manager instanceof CoreAliasManagerInterface) {
+        @trigger_error('The \\' . CoreAliasManagerInterface::class . ' interface is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Instead, use \\' . AliasManagerInterface::class . '. See https://drupal.org/node/3092086', E_USER_DEPRECATED);
+      }
+      else {
+        $actual_class = isset($alias_manager) ? get_class($alias_manager) : 'NULL';
+        throw new \InvalidArgumentException('An instance of \\' . AliasManagerInterface::class . ' was expected \\' . $actual_class . ' provided.');
+      }
+    }
+
     $this->aliasManager = $alias_manager;

IMHO a slightly less complex version of this would be better. I'd just keep the outer condition and then do standard constructor BC message with fallback to \Drupal::service().

Something like:

@trigger_error('Calling SiteinformationForm::__construct() with CoreAliasManagerInterface::class instead of AliasManagerInterface::class is deprecated in drupal:8.8.0. The new service will be required in drupal:9.0.0. See https://www.drupal.org/node/3035273', E_USER_DEPRECATED);
$alias_manager = \Drupal::service('path_alias.manager');

The current message tries to address my unspecific, wishful-thinking comment about deprecating the interface, but this isn't the place for it and is actually missing the most important part.. *where* you need to make the change, the constructor of this specific class.

plach’s picture

Status: Needs work » Needs review
StatusFileSize
new51.73 KB
new13.24 KB

This addresses #9 and also fixes some indentation issues.

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php
    @@ -12,10 +12,10 @@
      *
    - *   @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0.
    - *   Use \Drupal\path_alias\EventSubscriber\PathAliasSubscriber.
    + * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0.
    + * Use \Drupal\path_alias\EventSubscriber\PathAliasSubscriber.
    

    Well, both are wrong, actually :) like @todo, @deprecated should be one space in and then the following lines 3.

    Wasn't sure if I should still set it to RTBC, but it is in there quite often, so maybe a bit much to clean up pre-commit?

  2. +++ b/core/modules/path_alias/tests/src/Unit/DeprecatedClassesTest.php
    @@ -171,6 +171,33 @@ public function testAliasWhitelist() {
    +  /**
    +   * @covers \Drupal\system\Form\SiteInformationForm::__construct
    +   *
    +   * @expectedDeprecation Calling \Drupal\system\Form\SiteInformationForm::__construct with \Drupal\Core\Path\AliasManagerInterface instead of \Drupal\path_alias\AliasManagerInterface is deprecated in drupal:8.8.0. The new service will be required in drupal:9.0.0. See https://www.drupal.org/node/3092086
    +   */
    +  public function testDeprecatedSystemInformationFormConstructorParameters() {
    +    $this->assertDeprecatedConstructorParameter(SiteInformationForm::class);
    

    We usually don't bother with BC tests for constructors, entity manager conversion would probably still not be done if that would have been necessary. But we have it now, and since we're super late with this, it doesn't hurt to be extra careful :)

berdir’s picture

This is how I believe it should be, like other comments, it should only add linebreaks when the next word would be over 80 characters and mostly we finish it with .. instead. A little bit strange here as it's then always just the Use on the same line but so be it.

Edit: great, managed to upload it twice.

berdir’s picture

plach’s picture

Interdiff looks good to me

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Lets say we've reviewed each others changes then, I just change those comments, so setting back to RTBC which it already was before by @jibran.

jibran’s picture

Yup, RTBC +1, the latest changes look good as well.

  • catch committed 7585b6e on 9.0.x
    Issue #3094292 by plach, Berdir: Remove usages of deprecated path alias...
catch’s picture

Status: Reviewed & tested by the community » Needs work

Had to resolve a minor merge conflict and a couple of coding style issues on commit to 9.0.x - which I've already pushed. But this doesn't apply to 8.9.x any more either, so needs a re-roll there.

jibran’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new3.45 KB
new51.76 KB

Here you go.

  • catch committed 4345267 on 8.9.x
    Issue #3094292 by plach, Berdir, jibran: Remove usages of deprecated...

  • catch committed 9953008 on 8.8.x
    Issue #3094292 by plach, Berdir, jibran: Remove usages of deprecated...
catch’s picture

Version: 8.9.x-dev » 8.8.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.8.x and 8.8.x, thanks!

plach’s picture

Issue summary: View changes

Fixed typo in the IS

xjm’s picture

I think this broke 9.0.x HEAD -- no test runs back there against 9.0.x.
https://www.drupal.org/pift-ci-job/1474419

catch’s picture

Version: 8.8.x-dev » 9.0.x-dev
Status: Fixed » Needs work

Reverted against 9.0.x (but left in 8.8.x and 8.9.x that had proper test runs).

  • catch committed f506b49 on 9.0.x
    Revert "Issue #3094292 by plach, Berdir: Remove usages of deprecated...
jibran’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new2.31 KB
new52.02 KB

Here is the reroll.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 27: 3094292-27.patch, failed testing. View results

ravi.shankar’s picture

Status: Needs work » Needs review
StatusFileSize
new51.8 KB

Here I have tried to re-roll the patch.

Status: Needs review » Needs work

The last submitted patch, 29: 3094292-29.patch, failed testing. View results

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new54.33 KB
new2.53 KB

Took me a moment to understand this. These workspaces kernel tests were interacting with the path_aliases services without enabling the module. We didn't notice this in 8.x due to the BC in KernelTestBase that always enables it.

The interdiff should probably also be backported to 8.x branches for consistency?

(3094292-31-workspaces-path-alias.patch both the interdiff and the patch for D8)

The last submitted patch, 31: 3094292-31.patch, failed testing. View results

berdir’s picture

StatusFileSize
new55.44 KB
new3.64 KB

Two more kernel test that need path_alias. Since this was hold back from 9.0.x, I'm actually wondering if we don't want to move forward here and just commit a patch that updates the code without BC? We just have to remove the BC layer & tests again anyway?

berdir’s picture

StatusFileSize
new48.62 KB
new9.47 KB

Here's a version for 9.0.x without the BC layer and legacy tests. The existing parts we can remove in #3092090: Remove legacy Path Alias subsystem. Thoughts? That's a bunch of classes that we don't have to touch again, at least not until we actually make the module optional.

plach’s picture

Status: Needs review » Reviewed & tested by the community

Makes sense to me :)

  • catch committed ac65a88 on 9.0.x
    Issue #3094292 by Berdir, plach, jibran, ravi.shankar: Remove usages of...

  • catch committed 9b9965d on 8.9.x
    Issue #3094292 by Berdir, plach, jibran, ravi.shankar: Remove usages of...

  • catch committed f2407f9 on 8.8.x
    Issue #3094292 by Berdir, plach, jibran, ravi.shankar: Remove usages of...
catch’s picture

Version: 9.0.x-dev » 8.8.x-dev
Status: Reviewed & tested by the community » Fixed

Makes sense to skip adding the bc layer to 9.x only to take it away again and avoid relying on the bc layer in 8.x. Committed/pushed to 9.0.x/8.9.x/8.8.x, thanks!

  • xjm committed accde78 on 8.8.x
    Revert "Issue #3094292 by Berdir, plach, jibran, ravi.shankar: Remove...

  • xjm committed 4ea1bb4 on 8.9.x
    Revert "Issue #3094292 by Berdir, plach, jibran, ravi.shankar: Remove...

  • xjm committed 4b12049 on 9.0.x
    Revert "Issue #3094292 by Berdir, plach, jibran, ravi.shankar: Remove...

xjm credited larowlan.

xjm’s picture

Status: Fixed » Needs work

This introduced test failures on PHP 7.0 so I've reverted it. I initially considered leaving it in 9.0 since it requires PHP 7.2 and is therefore not affected, but that would risk the 8.9 commit diverging from the 9.0 one which we don't want.

Per @larowlan:

on 7.0 you have to use __toString but that is deprecated in 7.1 where you have to use ::getName()
so perhaps we need version juggling :crying_cat_face:

larowlan’s picture

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new724 bytes
new4.34 KB
new48.62 KB

> I initially considered leaving it in 9.0 since it requires PHP 7.2 and is therefore not affected, but that would risk the 8.9 commit diverging from the 9.0 one which we don't want.

The test that fails was not added to 9.0.x because it's only a legacy test for BC. So IMHO, for 9.0.x, #34 is still the patch that should be committed (again). Wouldn't have been necessary to revert there, but I see how this issue is becoming very confusing.

Also, for 8.8.x, only the follow-up commit for test consistency from #33 was reverted, which will not actually fix the test fails. As I said, this issue is a mess :-/

I actually don't have PHP 7.0, but my understanding is that this should work then. It does on 7.2. Note that the ? .. : check is necessary because we check with isset() below and (string) $type is an empty string.

Also, for consistency, again re-uploading the 9.0.x patch from #34.(which was actually named 33, I changed that but it's the same patch)

  • xjm committed fb30afb on 8.8.x
    Revert "Issue #3094292 by plach, Berdir, jibran: Remove usages of...

  • xjm committed ef4281e on 8.9.x
    Revert "Issue #3094292 by plach, Berdir, jibran: Remove usages of...

  • xjm committed 1a3aa31 on 9.0.x
    Revert "Revert "Issue #3094292 by plach, Berdir: Remove usages of...
xjm’s picture

Status: Needs review » Needs work

Sharp eyes, @Berdir. The two commits have the same title and were separated from each other in the log by other commits. I've reverted the earlier one now... 🤞

xjm’s picture

OK another problem here is that there were no PHP 7.0 environments tested on commit. I think maybe I set it up that way thinking that PHP 7.0 is EOL, but it meant that we didn't know for days that it was broken -- only when I started reading my work email on a Sunday night. 🙄I've changed that so the 7.0 environment is tested on commit. We should probably leave it that way until EOL.

xjm’s picture

Status: Needs work » Needs review

Oops, xposted status.

berdir’s picture

Aww, I was hoping we wouldn't have to do that, testbot is broken anyway right now :)

But fine, for 8.x, we now need a combined patch of the two commits against 8.8.x + the interdiff from #46, will do that later today if nobody beats me to it.

jibran’s picture

Assigned: Unassigned » jibran

On it.

jibran’s picture

Assigned: jibran » Unassigned
StatusFileSize
new55.4 KB
new55.44 KB

Here we go.

jibran’s picture

  • catch committed 3a4d788 on 9.0.x
    Revert "Revert "Revert (yes really) "Issue #3094292 by plach, Berdir:...
berdir’s picture

Status: Needs review » Reviewed & tested by the community

As discussed in slack, the revert of the revert in 9.0.x was not a mistake, per #46, the 7.0 bug exists in the legacy test for the BC layer that we did not commit to 9.0.x.

For the same reason, "3094292-55-9.0.x.patch" in comment #55 is the direct port of the D8 patch in the same comment, but we should commit "3094292-34-no-bc.patch" from #46 to 9.0.x.

It's probably cleaner to just to a regular commit of that again instead of reverting the revert of the revert of the revert :p

I did verify that the 8.8.x patch does what it should by comparing it against the commit before the revert-dance started:

$ git diff f2407f9fc4
diff --git a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php
index 3e17d0beda..80984331f2 100644
--- a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php
+++ b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php
@@ -47,7 +47,7 @@ class ContentModerationStateTest extends KernelTestBase {
     'content_translation',
     'text',
     'workflows',
-    'path_alias',
+    'path_alias'
   ];
 
   /**
diff --git a/core/modules/path_alias/tests/src/Unit/DeprecatedClassesTest.php b/core/modules/path_alias/tests/src/Unit/DeprecatedClassesTest.php
index 347e778190..1b54403039 100644
--- a/core/modules/path_alias/tests/src/Unit/DeprecatedClassesTest.php
+++ b/core/modules/path_alias/tests/src/Unit/DeprecatedClassesTest.php
@@ -221,7 +221,7 @@ public function assertDeprecatedConstructorParameter($tested_class_name) {
       }
       else {
         $type = $parameter->getType();
-        $class_name = $type ? $type->getName() : NULL;
+        $class_name = $type ? (string) $type : NULL;
       }
       $args[$name] = isset($class_name) && $class_name !== 'array' ? $this->prophesize($class_name)->reveal() : [];
     }
diff --git a/core/modules/system/src/Form/SiteInformationForm.php b/core/modules/system/src/Form/SiteInformationForm.php
index c4d95b53de..1bf6550bac 100644
--- a/core/modules/system/src/Form/SiteInformationForm.php
+++ b/core/modules/system/src/Form/SiteInformationForm.php
@@ -55,7 +55,7 @@ public function __construct(ConfigFactoryInterface $config_factory, $alias_manag
     parent::__construct($config_factory);
 
     if (!$alias_manager instanceof AliasManagerInterface) {
-      @trigger_error('Calling \\' . __METHOD__ . ' with \\' . CoreAliasManagerInterface::class . ' instead of \\' . AliasManagerInterface::class . ' is deprecated in drupal:8.8.0. The new service will be required in drupal:9.0.0. See https://www.drupal.org/node/3092086', E_USER_DEPRECATED);
+      @trigger_error('Calling \\' . __METHOD__  . ' with \\' . CoreAliasManagerInterface::class . ' instead of \\' . AliasManagerInterface::class . ' is deprecated in drupal:8.8.0. The new service will be required in drupal:9.0.0. See https://www.drupal.org/node/3092086', E_USER_DEPRECATED);
       $alias_manager = \Drupal::service('path_alias.manager');
     }
 
diff --git a/core/modules/system/src/Plugin/Condition/RequestPath.php b/core/modules/system/src/Plugin/Condition/RequestPath.php
index 38dc216ca1..dc53be1183 100644
--- a/core/modules/system/src/Plugin/Condition/RequestPath.php
+++ b/core/modules/system/src/Plugin/Condition/RequestPath.php
@@ -72,7 +72,7 @@ public function __construct($alias_manager, PathMatcherInterface $path_matcher,
     parent::__construct($configuration, $plugin_id, $plugin_definition);
 
     if (!$alias_manager instanceof AliasManagerInterface) {
-      @trigger_error('Calling \\' . __METHOD__ . ' with \\' . CoreAliasManagerInterface::class . ' instead of \\' . AliasManagerInterface::class . ' is deprecated in drupal:8.8.0. The new service will be required in drupal:9.0.0. See https://www.drupal.org/node/3092086', E_USER_DEPRECATED);
+      @trigger_error('Calling \\' . __METHOD__  . ' with \\' . CoreAliasManagerInterface::class . ' instead of \\' . AliasManagerInterface::class . ' is deprecated in drupal:8.8.0. The new service will be required in drupal:9.0.0. See https://www.drupal.org/node/3092086', E_USER_DEPRECATED);
       $alias_manager = \Drupal::service('path_alias.manager');
     }
 
diff --git a/core/modules/views/src/Plugin/views/argument_default/Raw.php b/core/modules/views/src/Plugin/views/argument_default/Raw.php
index 048e37b9f9..ad5abe1cea 100644
--- a/core/modules/views/src/Plugin/views/argument_default/Raw.php
+++ b/core/modules/views/src/Plugin/views/argument_default/Raw.php
@@ -54,7 +54,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
     parent::__construct($configuration, $plugin_id, $plugin_definition);
 
     if (!$alias_manager instanceof AliasManagerInterface) {
-      @trigger_error('Calling \\' . __METHOD__ . ' with \\' . CoreAliasManagerInterface::class . ' instead of \\' . AliasManagerInterface::class . ' is deprecated in drupal:8.8.0. The new service will be required in drupal:9.0.0. See https://www.drupal.org/node/3092086', E_USER_DEPRECATED);
+      @trigger_error('Calling \\' . __METHOD__  . ' with \\' . CoreAliasManagerInterface::class . ' instead of \\' . AliasManagerInterface::class . ' is deprecated in drupal:8.8.0. The new service will be required in drupal:9.0.0. See https://www.drupal.org/node/3092086', E_USER_DEPRECATED);
       $alias_manager = \Drupal::service('path_alias.manager');
     }
 

So the only differences are the actual PHP 7.0 fix, whitespace fixes in the deprecation messages (which is again for code that doesn't need to be in 9.0.x) and that missing trailing comma for the module list in that one test, that can maybe be fixed on commit?

  • catch committed 475ad55 on 9.0.x
    Issue #3094292 by Berdir, jibran, plach, ravi.shankar, xjm: Remove...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 9.0.x/8.9.x/8.8.x, hopefully for the last time ;) Thanks everyone!

  • catch committed 32e66ac on 8.8.x
    Issue #3094292 by Berdir, jibran, plach, ravi.shankar, xjm: Remove...

  • catch committed 8fc1702 on 8.9.x
    Issue #3094292 by Berdir, jibran, plach, ravi.shankar, xjm: Remove...
xjm’s picture

🥁

Status: Fixed » Closed (fixed)

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