22
33namespace Drush \Drupal \Migrate ;
44
5+ use Drupal \Component \Utility \DeprecationHelper ;
56use Drupal \Core \DependencyInjection \ContainerBuilder ;
67use Drupal \Core \DependencyInjection \ServiceModifierInterface ;
7- use Symfony \Component \DependencyInjection \Exception \ParameterNotFoundException ;
88
99/**
1010 * Registers a new migrate_prepare_row hook implementation.
@@ -26,21 +26,41 @@ public function alter(ContainerBuilder $container): void
2626 return ;
2727 }
2828
29- if (!$ container ->hasParameter ('hook_implementations_map ' )) {
30- return ;
31- }
32-
33- $ map = $ container ->getParameter ('hook_implementations_map ' );
3429 $ hook = 'migrate_prepare_row ' ;
3530 $ class = MigrateRunnerHooks::class;
3631 $ method = 'prepareRow ' ;
37- $ container ->register ($ class , $ class )
38- ->addTag ('kernel.event_listener ' , [
39- 'event ' => 'drupal_hook. ' . $ hook ,
40- 'method ' => $ method ,
41- 'priority ' => 0 ,
42- ])->setAutowired (true );
43- $ map [$ hook ][$ class ][$ method ] = 'system ' ;
44- $ container ->setParameter ('hook_implementations_map ' , $ map );
32+
33+ // Remove deprecation layer when support for Drupal <11.3 ends.
34+ // @see https://www.drupal.org/node/3550627
35+ DeprecationHelper::backwardsCompatibleCall (
36+ currentVersion: \Drupal::VERSION ,
37+ deprecatedVersion: '11.3.0 ' ,
38+ currentCallable: function () use ($ container , $ class , $ hook , $ method ): void {
39+ if (!$ container ->hasParameter ('.hook_data ' )) {
40+ return ;
41+ }
42+
43+ $ map = $ container ->getParameter ('.hook_data ' );
44+ $ identifier = "$ class: $ method " ;
45+ $ map ['hook_list ' ][$ hook ] = [$ identifier => 'system ' ] + ($ map ['hook_list ' ][$ hook ] ?? []);
46+ $ container ->register ($ class , $ class )->setAutowired (true );
47+ $ container ->setParameter ('.hook_data ' , $ map );
48+ },
49+ deprecatedCallable: function () use ($ container , $ class , $ hook , $ method ): void {
50+ if (!$ container ->hasParameter ('hook_implementations_map ' )) {
51+ return ;
52+ }
53+
54+ $ map = $ container ->getParameter ('hook_implementations_map ' );
55+ $ container ->register ($ class , $ class )
56+ ->addTag ('kernel.event_listener ' , [
57+ 'event ' => 'drupal_hook. ' . $ hook ,
58+ 'method ' => $ method ,
59+ 'priority ' => 0 ,
60+ ])->setAutowired (true );
61+ $ map [$ hook ][$ class ][$ method ] = 'system ' ;
62+ $ container ->setParameter ('hook_implementations_map ' , $ map );
63+ }
64+ );
4565 }
4666}
0 commit comments