ModuleInstaller.php 26.3 KB
Newer Older
1
2
3
4
<?php

namespace Drupal\Core\Extension;

5
use Drupal\Core\Cache\Cache;
6
7
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\DrupalKernelInterface;
8
9
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Entity\FieldableEntityInterface;
10
use Drupal\Core\Serialization\Yaml;
11
12
13
14

/**
 * Default implementation of the module installer.
 *
15
 * It registers the module in config, installs its own configuration,
16
 * installs the schema, updates the Drupal kernel and more.
17
18
19
20
21
 *
 * We don't inject dependencies yet, as we would need to reload them after
 * each installation or uninstallation of a module.
 * https://www.drupal.org/project/drupal/issues/2350111 for example tries to
 * solve this dilemma.
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 */
class ModuleInstaller implements ModuleInstallerInterface {

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * The drupal kernel.
   *
   * @var \Drupal\Core\DrupalKernelInterface
   */
  protected $kernel;

  /**
   * The app root.
   *
   * @var string
   */
  protected $root;

46
47
48
49
50
51
52
  /**
   * The uninstall validators.
   *
   * @var \Drupal\Core\Extension\ModuleUninstallValidatorInterface[]
   */
  protected $uninstallValidators;

53
54
55
56
57
58
59
60
61
62
63
64
65
  /**
   * Constructs a new ModuleInstaller instance.
   *
   * @param string $root
   *   The app root.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   * @param \Drupal\Core\DrupalKernelInterface $kernel
   *   The drupal kernel.
   *
   * @see \Drupal\Core\DrupalKernel
   * @see \Drupal\Core\CoreServiceProvider
   */
66
  public function __construct($root, ModuleHandlerInterface $module_handler, DrupalKernelInterface $kernel) {
67
68
69
70
71
    $this->root = $root;
    $this->moduleHandler = $module_handler;
    $this->kernel = $kernel;
  }

72
73
74
75
76
77
78
  /**
   * {@inheritdoc}
   */
  public function addUninstallValidator(ModuleUninstallValidatorInterface $uninstall_validator) {
    $this->uninstallValidators[] = $uninstall_validator;
  }

79
80
81
82
  /**
   * {@inheritdoc}
   */
  public function install(array $module_list, $enable_dependencies = TRUE) {
83
    $extension_config = \Drupal::configFactory()->getEditable('core.extension');
84
85
86
87
88
89
90
91
92
93
    // Get all module data so we can find dependencies and sort and find the
    // core requirements. The module list needs to be reset so that it can
    // re-scan and include any new modules that may have been added directly
    // into the filesystem.
    $module_data = \Drupal::service('extension.list.module')->reset()->getList();
    foreach ($module_list as $module) {
      if (!empty($module_data[$module]->info['core_incompatible'])) {
        throw new MissingDependencyException("Unable to install modules: module '$module' is incompatible with this version of Drupal core.");
      }
    }
94
    if ($enable_dependencies) {
95
      $module_list = $module_list ? array_combine($module_list, $module_list) : [];
96
      if ($missing_modules = array_diff_key($module_list, $module_data)) {
97
        // One or more of the given modules doesn't exist.
98
        throw new MissingDependencyException(sprintf('Unable to install modules %s due to missing modules %s.', implode(', ', $module_list), implode(', ', $missing_modules)));
99
100
101
      }

      // Only process currently uninstalled modules.
102
      $installed_modules = $extension_config->get('module') ?: [];
103
104
105
106
107
108
      if (!$module_list = array_diff_key($module_list, $installed_modules)) {
        // Nothing to do. All modules already installed.
        return TRUE;
      }

      // Add dependencies to the list. The new modules will be processed as
109
110
      // the foreach loop continues.
      foreach ($module_list as $module => $value) {
111
112
113
        foreach (array_keys($module_data[$module]->requires) as $dependency) {
          if (!isset($module_data[$dependency])) {
            // The dependency does not exist.
114
            throw new MissingDependencyException("Unable to install modules: module '$module' is missing its dependency module $dependency.");
115
116
117
118
          }

          // Skip already installed modules.
          if (!isset($module_list[$dependency]) && !isset($installed_modules[$dependency])) {
119
120
121
            if ($module_data[$dependency]->info['core_incompatible']) {
              throw new MissingDependencyException("Unable to install modules: module '$module'. Its dependency module '$dependency' is incompatible with this version of Drupal core.");
            }
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
            $module_list[$dependency] = $dependency;
          }
        }
      }

      // Set the actual module weights.
      $module_list = array_map(function ($module) use ($module_data) {
        return $module_data[$module]->sort;
      }, $module_list);

      // Sort the module list by their weights (reverse).
      arsort($module_list);
      $module_list = array_keys($module_list);
    }

    // Required for module installation checks.
    include_once $this->root . '/core/includes/install.inc';

140
141
142
    /** @var \Drupal\Core\Config\ConfigInstaller $config_installer */
    $config_installer = \Drupal::service('config.installer');
    $sync_status = $config_installer->isSyncing();
143
    if ($sync_status) {
144
      $source_storage = $config_installer->getSourceStorage();
145
    }
146
    $modules_installed = [];
147
148
149
150
151
    foreach ($module_list as $module) {
      $enabled = $extension_config->get("module.$module") !== NULL;
      if (!$enabled) {
        // Throw an exception if the module name is too long.
        if (strlen($module) > DRUPAL_EXTENSION_NAME_MAX_LENGTH) {
152
          throw new ExtensionNameLengthException("Module name '$module' is over the maximum allowed length of " . DRUPAL_EXTENSION_NAME_MAX_LENGTH . ' characters');
153
154
        }

155
156
157
158
        // Load a new config object for each iteration, otherwise changes made
        // in hook_install() are not reflected in $extension_config.
        $extension_config = \Drupal::configFactory()->getEditable('core.extension');

159
160
        // Check the validity of the default configuration. This will throw
        // exceptions if the configuration is not valid.
161
        $config_installer->checkConfigurationToInstall('module', $module);
162

163
164
        // Save this data without checking schema. This is a performance
        // improvement for module installation.
165
166
167
        $extension_config
          ->set("module.$module", 0)
          ->set('module', module_config_sort($extension_config->get('module')))
168
          ->save(TRUE);
169
170
171
172
173
174
175
176
177
178
179
180
181
182

        // Prepare the new module list, sorted by weight, including filenames.
        // This list is used for both the ModuleHandler and DrupalKernel. It
        // needs to be kept in sync between both. A DrupalKernel reboot or
        // rebuild will automatically re-instantiate a new ModuleHandler that
        // uses the new module list of the kernel. However, DrupalKernel does
        // not cause any modules to be loaded.
        // Furthermore, the currently active (fixed) module list can be
        // different from the configured list of enabled modules. For all active
        // modules not contained in the configured enabled modules, we assume a
        // weight of 0.
        $current_module_filenames = $this->moduleHandler->getModuleList();
        $current_modules = array_fill_keys(array_keys($current_module_filenames), 0);
        $current_modules = module_config_sort(array_merge($current_modules, $extension_config->get('module')));
183
        $module_filenames = [];
184
185
186
187
188
        foreach ($current_modules as $name => $weight) {
          if (isset($current_module_filenames[$name])) {
            $module_filenames[$name] = $current_module_filenames[$name];
          }
          else {
189
            $module_path = \Drupal::service('extension.list.module')->getPath($name);
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
            $pathname = "$module_path/$name.info.yml";
            $filename = file_exists($module_path . "/$name.module") ? "$name.module" : NULL;
            $module_filenames[$name] = new Extension($this->root, 'module', $pathname, $filename);
          }
        }

        // Update the module handler in order to load the module's code.
        // This allows the module to participate in hooks and its existence to
        // be discovered by other modules.
        // The current ModuleHandler instance is obsolete with the kernel
        // rebuild below.
        $this->moduleHandler->setModuleList($module_filenames);
        $this->moduleHandler->load($module);
        module_load_install($module);

205
206
207
208
        // Clear the static cache of the "extension.list.module" service to pick
        // up the new module, since it merges the installation status of modules
        // into its statically cached list.
        \Drupal::service('extension.list.module')->reset();
209
210
211
212

        // Update the kernel to include it.
        $this->updateKernel($module_filenames);

213
214
215
216
217
218
219
220
221
222
223
        // Replace the route provider service with a version that will rebuild
        // if routes used during installation. This ensures that a module's
        // routes are available during installation. This has to occur before
        // any services that depend on it are instantiated otherwise those
        // services will have the old route provider injected. Note that, since
        // the container is rebuilt by updating the kernel, the route provider
        // service is the regular one even though we are in a loop and might
        // have replaced it before.
        \Drupal::getContainer()->set('router.route_provider.old', \Drupal::service('router.route_provider'));
        \Drupal::getContainer()->set('router.route_provider', \Drupal::service('router.route_provider.lazy_builder'));

224
        // Allow modules to react prior to the installation of a module.
225
        $this->moduleHandler->invokeAll('module_preinstall', [$module]);
226
227
228
229

        // Now install the module's schema if necessary.
        drupal_install_schema($module);

230
        // Clear plugin manager caches.
231
        \Drupal::getContainer()->get('plugin.cache_clearer')->clearCachedDefinitions();
232
233
234
235
236
237
238
239
240

        // Set the schema version to the number of the last update provided by
        // the module, or the minimum core schema version.
        $version = \Drupal::CORE_MINIMUM_SCHEMA_VERSION;
        $versions = drupal_get_schema_versions($module);
        if ($versions) {
          $version = max(max($versions), $version);
        }

241
242
243
244
        // Notify interested components that this module's entity types and
        // field storage definitions are new. For example, a SQL-based storage
        // handler can use this as an opportunity to create the necessary
        // database tables.
245
        // @todo Clean this up in https://www.drupal.org/node/2350111.
246
        $entity_type_manager = \Drupal::entityTypeManager();
247
        $update_manager = \Drupal::entityDefinitionUpdateManager();
248
249
250
        /** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */
        $entity_field_manager = \Drupal::service('entity_field.manager');
        foreach ($entity_type_manager->getDefinitions() as $entity_type) {
251
252
          $is_fieldable_entity_type = $entity_type->entityClassImplements(FieldableEntityInterface::class);

253
          if ($entity_type->getProvider() == $module) {
254
255
256
257
258
259
            if ($is_fieldable_entity_type) {
              $update_manager->installFieldableEntityType($entity_type, $entity_field_manager->getFieldStorageDefinitions($entity_type->id()));
            }
            else {
              $update_manager->installEntityType($entity_type);
            }
260
          }
261
          elseif ($is_fieldable_entity_type) {
262
263
264
            // The module being installed may be adding new fields to existing
            // entity types. Field definitions for any entity type defined by
            // the module are handled in the if branch.
265
            foreach ($entity_field_manager->getFieldStorageDefinitions($entity_type->id()) as $storage_definition) {
266
267
268
269
270
271
272
273
274
275
276
277
              if ($storage_definition->getProvider() == $module) {
                // If the module being installed is also defining a storage key
                // for the entity type, the entity schema may not exist yet. It
                // will be created later in that case.
                try {
                  $update_manager->installFieldStorageDefinition($storage_definition->getName(), $entity_type->id(), $module, $storage_definition);
                }
                catch (EntityStorageException $e) {
                  watchdog_exception('system', $e, 'An error occurred while notifying the creation of the @name field storage definition: "!message" in %function (line %line of %file).', ['@name' => $storage_definition->getName()]);
                }
              }
            }
278
279
280
281
          }
        }

        // Install default configuration of the module.
282
        $config_installer = \Drupal::service('config.installer');
283
        if ($sync_status) {
284
          $config_installer
285
286
287
            ->setSyncing(TRUE)
            ->setSourceStorage($source_storage);
        }
288
        \Drupal::service('config.installer')->installDefaultConfig('module', $module);
289
290
291
292
293
294
295
296
297

        // If the module has no current updates, but has some that were
        // previously removed, set the version to the value of
        // hook_update_last_removed().
        if ($last_removed = $this->moduleHandler->invoke($module, 'update_last_removed')) {
          $version = max($version, $last_removed);
        }
        drupal_set_installed_schema_version($module, $version);

298
299
300
301
        // Ensure that all post_update functions are registered already. This
        // should include existing post-updates, as well as any specified as
        // having been previously removed, to ensure that newly installed and
        // updated sites have the same entries in the registry.
302
303
        /** @var \Drupal\Core\Update\UpdateRegistry $post_update_registry */
        $post_update_registry = \Drupal::service('update.post_update_registry');
304
        $post_update_registry->registerInvokedUpdates(array_merge($post_update_registry->getModuleUpdateFunctions($module), array_keys($post_update_registry->getRemovedPostUpdates($module))));
305

306
307
308
        // Record the fact that it was installed.
        $modules_installed[] = $module;

309
310
311
312
313
        // Drupal's stream wrappers needs to be re-registered in case a
        // module-provided stream wrapper is used later in the same request. In
        // particular, this happens when installing Drupal via Drush, as the
        // 'translations' stream wrapper is provided by Interface Translation
        // module and is later used to import translations.
314
        \Drupal::service('stream_wrapper_manager')->register();
315
316
317
318
319

        // Update the theme registry to include it.
        drupal_theme_rebuild();

        // Modules can alter theme info, so refresh theme data.
320
321
322
323
        // @todo ThemeHandler cannot be injected into ModuleHandler, since that
        //   causes a circular service dependency.
        // @see https://www.drupal.org/node/2208429
        \Drupal::service('theme_handler')->refreshInfo();
324
325

        // Allow the module to perform install tasks.
326
        $this->moduleHandler->invoke($module, 'install', [$sync_status]);
327
328

        // Record the fact that it was installed.
329
        \Drupal::logger('system')->info('%module module installed.', ['%module' => $module]);
330
331
332
333
334
      }
    }

    // If any modules were newly installed, invoke hook_modules_installed().
    if (!empty($modules_installed)) {
335
336
337
338
339
      // If the container was rebuilt during hook_install() it might not have
      // the 'router.route_provider.old' service.
      if (\Drupal::hasService('router.route_provider.old')) {
        \Drupal::getContainer()->set('router.route_provider', \Drupal::service('router.route_provider.old'));
      }
340
341
342
343
344
345
346
347
      if (!\Drupal::service('router.route_provider.lazy_builder')->hasRebuilt()) {
        // Rebuild routes after installing module. This is done here on top of
        // \Drupal\Core\Routing\RouteBuilder::destruct to not run into errors on
        // fastCGI which executes ::destruct() after the module installation
        // page was sent already.
        \Drupal::service('router.builder')->rebuild();
      }

348
      $this->moduleHandler->invokeAll('modules_installed', [$modules_installed, $sync_status]);
349
350
351
352
353
354
355
356
357
358
    }

    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
    // Get all module data so we can find dependencies and sort.
359
    $module_data = \Drupal::service('extension.list.module')->getList();
360
    $sync_status = \Drupal::service('config.installer')->isSyncing();
361
    $module_list = $module_list ? array_combine($module_list, $module_list) : [];
362
363
364
365
366
    if (array_diff_key($module_list, $module_data)) {
      // One or more of the given modules doesn't exist.
      return FALSE;
    }

367
    $extension_config = \Drupal::configFactory()->getEditable('core.extension');
368
    $installed_modules = $extension_config->get('module') ?: [];
369
370
371
372
373
374
    if (!$module_list = array_intersect_key($module_list, $installed_modules)) {
      // Nothing to do. All modules already uninstalled.
      return TRUE;
    }

    if ($uninstall_dependents) {
375
      $theme_list = \Drupal::service('extension.list.theme')->getList();
376

377
      // Add dependent modules to the list. The new modules will be processed as
378
379
      // the foreach loop continues.
      foreach ($module_list as $module => $value) {
380
        foreach (array_keys($module_data[$module]->required_by) as $dependent) {
381
382
          if (!isset($module_data[$dependent]) && !isset($theme_list[$dependent])) {
            // The dependent module or theme does not exist.
383
384
385
386
            return FALSE;
          }

          // Skip already uninstalled modules.
387
          if (isset($installed_modules[$dependent]) && !isset($module_list[$dependent])) {
388
389
390
391
392
393
            $module_list[$dependent] = $dependent;
          }
        }
      }
    }

394
395
396
397
398
    // Use the validators and throw an exception with the reasons.
    if ($reasons = $this->validateUninstall($module_list)) {
      foreach ($reasons as $reason) {
        $reason_message[] = implode(', ', $reason);
      }
399
      throw new ModuleUninstallValidatorException('The following reasons prevent the modules from being uninstalled: ' . implode('; ', $reason_message));
400
    }
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
    // Set the actual module weights.
    $module_list = array_map(function ($module) use ($module_data) {
      return $module_data[$module]->sort;
    }, $module_list);

    // Sort the module list by their weights.
    asort($module_list);
    $module_list = array_keys($module_list);

    // Only process modules that are enabled. A module is only enabled if it is
    // configured as enabled. Custom or overridden module handlers might contain
    // the module already, which means that it might be loaded, but not
    // necessarily installed.
    foreach ($module_list as $module) {

      // Clean up all entity bundles (including fields) of every entity type
      // provided by the module that is being uninstalled.
      // @todo Clean this up in https://www.drupal.org/node/2350111.
419
      $entity_type_manager = \Drupal::entityTypeManager();
420
      $entity_type_bundle_info = \Drupal::service('entity_type.bundle.info');
421
      foreach ($entity_type_manager->getDefinitions() as $entity_type_id => $entity_type) {
422
        if ($entity_type->getProvider() == $module) {
423
          foreach (array_keys($entity_type_bundle_info->getBundleInfo($entity_type_id)) as $bundle) {
424
            \Drupal::service('entity_bundle.listener')->onBundleDelete($bundle, $entity_type_id);
425
426
427
428
429
          }
        }
      }

      // Allow modules to react prior to the uninstallation of a module.
430
      $this->moduleHandler->invokeAll('module_preuninstall', [$module]);
431
432
433

      // Uninstall the module.
      module_load_install($module);
434
      $this->moduleHandler->invoke($module, 'uninstall', [$sync_status]);
435
436

      // Remove all configuration belonging to the module.
437
      \Drupal::service('config.manager')->uninstall('module', $module);
438

439
440
441
442
      // In order to make uninstalling transactional if anything uses routes.
      \Drupal::getContainer()->set('router.route_provider.old', \Drupal::service('router.route_provider'));
      \Drupal::getContainer()->set('router.route_provider', \Drupal::service('router.route_provider.lazy_builder'));

443
444
445
446
      // Notify interested components that this module's entity types are being
      // deleted. For example, a SQL-based storage handler can use this as an
      // opportunity to drop the corresponding database tables.
      // @todo Clean this up in https://www.drupal.org/node/2350111.
447
      $update_manager = \Drupal::entityDefinitionUpdateManager();
448
449
450
      /** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */
      $entity_field_manager = \Drupal::service('entity_field.manager');
      foreach ($entity_type_manager->getDefinitions() as $entity_type) {
451
        if ($entity_type->getProvider() == $module) {
452
453
          $update_manager->uninstallEntityType($entity_type);
        }
454
        elseif ($entity_type->entityClassImplements(FieldableEntityInterface::CLASS)) {
455
456
457
          // The module being uninstalled might have added new fields to
          // existing entity types. This will add them to the deleted fields
          // repository so their data will be purged on cron.
458
          foreach ($entity_field_manager->getFieldStorageDefinitions($entity_type->id()) as $storage_definition) {
459
            if ($storage_definition->getProvider() == $module) {
460
461
462
              $update_manager->uninstallFieldStorageDefinition($storage_definition);
            }
          }
463
464
465
466
467
468
        }
      }

      // Remove the schema.
      drupal_uninstall_schema($module);

469
470
      // Remove the module's entry from the config. Don't check schema when
      // uninstalling a module since we are only clearing a key.
471
      \Drupal::configFactory()->getEditable('core.extension')->clear("module.$module")->save(TRUE);
472
473
474
475
476
477
478
479
480
481
482

      // Update the module handler to remove the module.
      // The current ModuleHandler instance is obsolete with the kernel rebuild
      // below.
      $module_filenames = $this->moduleHandler->getModuleList();
      unset($module_filenames[$module]);
      $this->moduleHandler->setModuleList($module_filenames);

      // Remove any potential cache bins provided by the module.
      $this->removeCacheBins($module);

483
484
485
486
      // Clear the static cache of the "extension.list.module" service to pick
      // up the new module, since it merges the installation status of modules
      // into its statically cached list.
      \Drupal::service('extension.list.module')->reset();
487

488
      // Clear plugin manager caches.
489
      \Drupal::getContainer()->get('plugin.cache_clearer')->clearCachedDefinitions();
490
491
492
493
494
495
496
497

      // Update the kernel to exclude the uninstalled modules.
      $this->updateKernel($module_filenames);

      // Update the theme registry to remove the newly uninstalled module.
      drupal_theme_rebuild();

      // Modules can alter theme info, so refresh theme data.
498
499
500
501
      // @todo ThemeHandler cannot be injected into ModuleHandler, since that
      //   causes a circular service dependency.
      // @see https://www.drupal.org/node/2208429
      \Drupal::service('theme_handler')->refreshInfo();
502

503
      \Drupal::logger('system')->info('%module module uninstalled.', ['%module' => $module]);
504

505
506
      $schema_store = \Drupal::keyValue('system.schema');
      $schema_store->delete($module);
507
508
509
510

      /** @var \Drupal\Core\Update\UpdateRegistry $post_update_registry */
      $post_update_registry = \Drupal::service('update.post_update_registry');
      $post_update_registry->filterOutInvokedUpdatesByModule($module);
511
    }
512
513
514
515
    // Rebuild routes after installing module. This is done here on top of
    // \Drupal\Core\Routing\RouteBuilder::destruct to not run into errors on
    // fastCGI which executes ::destruct() after the Module uninstallation page
    // was sent already.
516
    \Drupal::service('router.builder')->rebuild();
517
518
519
    drupal_get_installed_schema_version(NULL, TRUE);

    // Let other modules react.
520
    $this->moduleHandler->invokeAll('modules_uninstalled', [$module_list, $sync_status]);
521

522
523
524
525
526
527
528
529
    // Flush all persistent caches.
    // Any cache entry might implicitly depend on the uninstalled modules,
    // so clear all of them explicitly.
    $this->moduleHandler->invokeAll('cache_flush');
    foreach (Cache::getBins() as $service_id => $cache_backend) {
      $cache_backend->deleteAll();
    }

530
531
532
533
534
535
536
537
538
539
540
    return TRUE;
  }

  /**
   * Helper method for removing all cache bins registered by a given module.
   *
   * @param string $module
   *   The name of the module for which to remove all registered cache bins.
   */
  protected function removeCacheBins($module) {
    $service_yaml_file = drupal_get_path('module', $module) . "/$module.services.yml";
541
542
543
544
545
546
547
548
549
550
551
552
553
    if (!file_exists($service_yaml_file)) {
      return;
    }

    $definitions = Yaml::decode(file_get_contents($service_yaml_file));

    $cache_bin_services = array_filter(
      isset($definitions['services']) ? $definitions['services'] : [],
      function ($definition) {
        $tags = isset($definition['tags']) ? $definition['tags'] : [];
        foreach ($tags as $tag) {
          if (isset($tag['name']) && ($tag['name'] == 'cache.bin')) {
            return TRUE;
554
555
          }
        }
556
557
558
559
560
561
562
563
        return FALSE;
      }
    );

    foreach (array_keys($cache_bin_services) as $service_id) {
      $backend = $this->kernel->getContainer()->get($service_id);
      if ($backend instanceof CacheBackendInterface) {
        $backend->removeBin();
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
      }
    }
  }

  /**
   * Updates the kernel module list.
   *
   * @param string $module_filenames
   *   The list of installed modules.
   */
  protected function updateKernel($module_filenames) {
    // This reboots the kernel to register the module's bundle and its services
    // in the service container. The $module_filenames argument is taken over as
    // %container.modules% parameter, which is passed to a fresh ModuleHandler
    // instance upon first retrieval.
    $this->kernel->updateModules($module_filenames, $module_filenames);
    // After rebuilding the container we need to update the injected
    // dependencies.
582
583
    $container = $this->kernel->getContainer();
    $this->moduleHandler = $container->get('module_handler');
584
585
  }

586
587
588
589
  /**
   * {@inheritdoc}
   */
  public function validateUninstall(array $module_list) {
590
    $reasons = [];
591
592
593
594
595
    foreach ($module_list as $module) {
      foreach ($this->uninstallValidators as $validator) {
        $validation_reasons = $validator->validate($module);
        if (!empty($validation_reasons)) {
          if (!isset($reasons[$module])) {
596
            $reasons[$module] = [];
597
598
599
600
601
602
603
604
          }
          $reasons[$module] = array_merge($reasons[$module], $validation_reasons);
        }
      }
    }
    return $reasons;
  }

605
}