Problem/Motivation

Dynamic removal of hooks will not be supported for long, let's also remove the dependency on drush.

Also, it seems like the Migrate Boost module does not currently work in Drupal 10 with Drush 13.

Steps to reproduce

Try to block a module from hooking into the migration process using the standard method, and see that the module still hooks in.

Proposed resolution

Get version 2.x to work in Drupal 10 with Drush 13.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#25 3499285-refactor-to-decorate-25.patch16.64 KBgrevil
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

nicxvan created an issue. See original summary.

nicxvan’s picture

Version: 1.0.x-dev » 2.0.x-dev

ressa’s picture

ressa’s picture

Title: Refactor to decorate ModuleHandler instead of HMIA » Refactor to decorate ModuleHandler instead of HMIA, to make it work in Drupal 10 with Drush 13
Issue summary: View changes

Moving some description here, from duplicate issue.

joelpittet’s picture

In CheckCircularReferencesPass.php line 81:

  Circular reference detected for service "migrate_boost.module_handler", path: "migrate_boost.module_handler -> config.factory -> config.typed -> migrate_boost.module_handler".

Current code produces this error. I tried uninstalling and pre patch, and installing with patch with the same result.

nicxvan’s picture

What version of drupal?

joelpittet’s picture

Same in the title, drupal 10 and drush 13

joelpittet’s picture

Sorry, I applied it against 1.x, disregard my comment

joelpittet’s picture

I saw the same problem in 2.x

joelpittet’s picture

The MR still has this alter() static method call which doesn't exist any more:

function migrate_boost_module_implements_alter(&$implementations, $hook) {
  MigrateBoost::alter($implementations, $hook);
}

What's the plan for this?

joelpittet’s picture

MigrateBoost::isBoostActive() seems to be always not set. And the drush command doesn't seem to be available.
I think the command is missing a services yaml like:

  migrate_boost.commands:
    class: Drupal\migrate_boost\Commands\MigrateBoostCommands
    tags:
      - { name: drush.command }

and I think the namespace for the command should be
namespace Drupal\migrate_boost\Commands; instead of namespace Drupal\migrate_boost\Drush\Commands;

Thoughts?

joelpittet’s picture

RE #11, this is the error, I didn't make a commit because I don't have an idea what is supposed to happen with that, I suspect remove migrate_boost_module_implements_alter?

Error: Call to undefined method Drupal\migrate_boost\MigrateBoost::alter() in /var/www/html/public/modules/contrib/migrate_boost/migrate_boost.module on line 14 #0 /var/www/html/public/core/lib/Drupal/Core/Extension/ModuleHandler.php(552): migrate_boost_module_implements_alter()

joelpittet’s picture

Re #12, based on the Issue Summary goal of “let’s also remove the dependency on Drush,” I’m assuming we can remove the command entirely.

Since we are decorating the module handler, we also don’t need migrate_boost_module_implements_alter().

I’ll go ahead and remove them as I’m just trying to get this working. Let me know if I’ve overstepped in my haste!

nicxvan’s picture

No worries! HMIA does need to be removed, I don't recall if we need Drush still, I think it hooks into only affect migrations run with Drush.

Happy to have someone reviewing, I only work on this for a personal project so I've not had time to dig in further.

joelpittet’s picture

Thanks @nicxvan, I am not sure what HMIA is, I am guessing it's related to inheritance or something but google/ChatGPT didn't turn up good results.

nicxvan’s picture

hook_module_implements_alter == HMIA

joelpittet’s picture

Ah a Drupal acronym I've never heard of, thanks!

joelpittet’s picture

Status: Active » Needs review

Ok this is working for me now. My last commit got rid of isHookDisabled() calls without the new $module arg because it wasn't available without implementing getImplementationInfo() and buildImplementationInfo() and verifyImplementations() which isn't the end of the world but getting pretty complicated and likely not needed.

The alter methods are tricky, because they call some of the decorated methods inside themselves. It’s almost better to just leave them alone.

nicxvan’s picture

This looks great!

Gonna test it some now.

nicxvan’s picture

I think I can get behind dropping the ability to kill alter, but I think we need to handle invokeAllWith still.

Gonna work on this a bit.

nicxvan’s picture

What do you think of that?

Thanks for all of your help!

joelpittet’s picture

Thanks for the review!

I’ll look at it tomorrow when I am in.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

@nicxvan I had a look, trying it out IRL right now. The code looks good to me, going to mark this RTBC from my end as it does what is on the Tin ;)

grevil’s picture

StatusFileSize
new16.64 KB

Providing static patch for the time being.

grevil’s picture

Seems to work great! Currently, in the midst of migrating a large Drupal 6 site. If anything goes wrong related to this module, I'll comment here again!

Note, that the introduction of the new Decorator leads to an error when migrating d6 nodes. But that is unrelated to this module but rather a drupal core issue. I just created an issue + fix here: #3512815: "core/modules/node/src/Plugin/migrate/source/d6/Node.php" "__construct" method uses variable of type "ModuleHandler" instead of "ModuleHandlerInterface".

Otherwise, RTBC +1!

anybody’s picture

Confirming #26!

grevil’s picture

nicxvan’s picture

Thanks everyone, this is on my list!

nicxvan’s picture

Thank you everyone, I'm merging this, I did restrict this to 11.1 and above since this will only work there.

This version will be very short lived since ModuleHandler is refactored in 11.2. but we can cross that bridge when we get there.

  • nicxvan committed 645c269e on 2.0.x
    Resolve #3499285 "Refactor to decorate"
    
nicxvan’s picture

Status: Reviewed & tested by the community » Fixed
joelpittet’s picture

Aw man I was using this on Drupal 10 🥺

nicxvan’s picture

Sorry about that, but I don't see how this could have possibly worked on Drupal 10, Hooks are not events in Drupal 11 which this decoration assumes.

If you want to open another issue to add it back in I can reevaluate there.

joelpittet’s picture

I am quite sure I got this working in 10.x, but I put some time into making it work (whole time above was testing against 10.x ^^). Can I use #3520832: Consider adding Drupal 10 support back to version 2 as my other issue?

nicxvan’s picture

Yes, I created that one for you to test with. That reverts the only change I made in this issue after your work.

Status: Fixed » Closed (fixed)

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