|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Drush\Drupal\Migrate; |
| 4 | + |
| 5 | +use Drupal\Core\DependencyInjection\ContainerBuilder; |
| 6 | +use Drupal\Core\DependencyInjection\ServiceModifierInterface; |
| 7 | +use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException; |
| 8 | + |
| 9 | +/** |
| 10 | + * Registers a new migrate_prepare_row hook implementation. |
| 11 | + * |
| 12 | + * A new 'migrate_prepare_row' hook implementation in behalf of the system. |
| 13 | + * |
| 14 | + * @todo Deprecate this hook implementation when #2952291 lands. |
| 15 | + * @see https://www.drupal.org/project/drupal/issues/2952291 |
| 16 | + */ |
| 17 | +class MigrateRunnerServiceProvider implements ServiceModifierInterface |
| 18 | +{ |
| 19 | + /** |
| 20 | + * {@inheritdoc} |
| 21 | + */ |
| 22 | + public function alter(ContainerBuilder $container): void |
| 23 | + { |
| 24 | + $modules = $container->hasParameter('container.modules') ? $container->getParameter('container.modules') : []; |
| 25 | + if (!isset($modules['migrate'])) { |
| 26 | + return; |
| 27 | + } |
| 28 | + |
| 29 | + if (!$container->hasParameter('hook_implementations_map')) { |
| 30 | + return; |
| 31 | + } |
| 32 | + |
| 33 | + $map = $container->getParameter('hook_implementations_map'); |
| 34 | + $hook = 'migrate_prepare_row'; |
| 35 | + $class = MigrateRunnerHooks::class; |
| 36 | + $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); |
| 45 | + } |
| 46 | +} |
0 commit comments