ModuleUninstallValidatorInterface.php 1.36 KB
Newer Older
1 2 3 4 5 6
<?php

namespace Drupal\Core\Extension;

/**
 * Common interface for module uninstall validators.
7 8 9 10
 *
 * A module uninstall validator must implement this interface and be defined in
 * a Drupal @link container service @endlink that is tagged
 * module_install.uninstall_validator.
11 12 13 14 15 16
 */
interface ModuleUninstallValidatorInterface {

  /**
   * Determines the reasons a module can not be uninstalled.
   *
17 18 19
   * Example implementation:
   * @code
   * public function validate($module) {
20
   *   $entity_types = $this->entityTypeManager->getDefinitions();
21 22
   *   $reasons = array();
   *   foreach ($entity_types as $entity_type) {
23
   *     if ($module == $entity_type->getProvider() && $entity_type instanceof ContentEntityTypeInterface && $this->entityTypeManager->getStorage($entity_type->id())->hasData()) {
24 25 26 27 28 29 30
   *       $reasons[] = $this->t('There is content for the entity type: @entity_type', array('@entity_type' => $entity_type->getLabel()));
   *     }
   *   }
   *   return $reasons;
   * }
   * @endcode
   *
31 32 33 34 35
   * @param string $module
   *   A module name.
   *
   * @return string[]
   *   An array of reasons the module can not be uninstalled, empty if it can.
36 37 38
   *   Each reason should not end with any punctuation since multiple reasons
   *   can be displayed together.
   *
39
   * @see template_preprocess_system_modules_uninstall()
40 41
   */
  public function validate($module);
42

43
}