Problem/Motivation

  2x: ModuleHandlerInterface::getImplementations() is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Instead you should use ModuleHandlerInterface::invokeAllWith() for hook invocations, or you should use ModuleHandlerInterface::hasImplementations() to determine if hooks implementations exist. See https://www.drupal.org/node/3000490

Needs a conditional like in the field_group D10 issue. Alternatively, we could possibly call it like a regular hook and check if any module returned TRUE. slightly less efficient, as this is currently optimized to return TRUE on the first module returning TRUE.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Berdir created an issue. See original summary.

ada hernandez’s picture

Adding a patch to remove the ModuleHandler::getImplementations() deprecation.

berdir’s picture

Status: Active » Needs work

Thanks, there are two issues with it:

a), we need to keep both versions, to support 9.3 still. See the patch in #3278537: D10 compatibility | Declaration of Drupal\field_group\Routing\RouteSubscriber::getSubscribedEvents() must be compatible with Drupal\Core\Routing\RouteSubscriberBase::getSubscribedEvents(), check core version, then do one or the other.
b) I don't think this is working. You are now inside a nested function, that return TRUE/FALSE is not going anywhere. seems like we don't have test coverage of this? We need to have a by reference variable that we set to TRUE/FALSE and then return that. Also no need to make $results an array. And to keep the optimization, we need to check if $result is already TRUE and skip the call then, so:

if ($result === FALSE) {
  $result = $hook();
}
s_bhandari’s picture

Hi,

Patch added for the same. Please review.

Thanks.

s_bhandari’s picture

Status: Needs work » Needs review
berdir’s picture

Status: Needs review » Needs work
+++ b/src/AliasUniquifier.php
@@ -119,15 +119,28 @@ class AliasUniquifier implements AliasUniquifierInterface {
+    if (method_exists($this->moduleHandler, 'invokeAllWith')) {
+      $this->moduleHandler->invokeAllWith($hook, function (callable $hook, string $module) {
+        $results[$module] = $hook();
+        if (!empty($results)) {
+          // As soon as the first module says that an alias is in fact reserved,
+          // then there is no point in checking the rest of the modules.
+          return TRUE;
+        }

this stores the return in a results array but then uses it as a boolean. you need to assign to $results directly.

Also, you can't return anymore, you're inside a function, it goes nowhere. you need to use (&$result) so that the result if it can be returned.

benjifisher’s picture

benjifisher’s picture

Assigned: benjifisher » Unassigned
StatusFileSize
new1021 bytes

Here is a patch that implements the solution proposed in the issue summary.

I am not providing an interdiff, since this is a different approach from the earlier patches.

benjifisher’s picture

Status: Needs work » Needs review
StatusFileSize
new749 bytes

Here is a patch that implements yet another approach. This should work the same way with both Drupal 10 (tested) and 9.3 (untested).

berdir’s picture

StatusFileSize
new3.44 KB

Interesting. I guess that works, I do wonder what the performance impact is, getImplementations() is cached and this is likely going to call hasImplementations() 100+ times on sites with many modules. And most sites won't actually have an implementation of this hook.

So I'll go with #8, we can eventually clean this up and do the check directly in the callback.

Also sneaking in D10 test fixes that didn't fail before.

Status: Needs review » Needs work

The last submitted patch, 10: pathauto-3293221-10.patch, failed testing. View results

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new3.4 KB
new2.05 KB

Ah, need to pass in the Url object, forgot that you can do that.

  • Berdir committed 34d606f on 8.x-1.x authored by benjifisher
    Issue #3293221 by Berdir, benjifisher, S_Bhandari, Ada Hernandez: D10:...
berdir’s picture

Status: Needs review » Fixed

Committed.

Status: Fixed » Closed (fixed)

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