FilterUninstallValidator::validate

public FilterUninstallValidator::validate($module)

Determines the reasons a module can not be uninstalled.

Example implementation:

public function validate($module) {
  $entity_types = $this->entityManager->getDefinitions();
  $reasons = array();
  foreach ($entity_types as $entity_type) {
    if ($module == $entity_type->getProvider() && $entity_type instanceof ContentEntityTypeInterface && $this->entityManager->getStorage($entity_type->id())->hasData()) {
      $reasons[] = $this->t('There is content for the entity type: @entity_type', array('@entity_type' => $entity_type->getLabel()));
    }
  }
  return $reasons;
}

Parameters

string $module: A module name.

Return value

string[] An array of reasons the module can not be uninstalled, empty if it can. Each reason should not end with any punctuation since multiple reasons can be displayed together.

Overrides ModuleUninstallValidatorInterface::validate

See also

template_preprocess_system_modules_uninstall()

File

core/modules/filter/src/FilterUninstallValidator.php, line 51

Class

FilterUninstallValidator
Prevents uninstallation of modules providing used filter plugins.

Namespace

Drupal\filter

Code

public function validate($module) {
  $reasons = [];
  // Get filter plugins supplied by this module.
  if ($filter_plugins = $this->getFilterDefinitionsByProvider($module)) {
    $used_in = [];
    // Find out if any filter formats have the plugin enabled.
    foreach ($this->getEnabledFilterFormats() as $filter_format) {
      $filters = $filter_format->filters();
      foreach ($filter_plugins as $filter_plugin) {
        if ($filters->has($filter_plugin['id']) && $filters->get($filter_plugin['id'])->status) {
          $used_in[] = $filter_format->label();
          break;
        }
      }
    }
    if (!empty($used_in)) {
      $reasons[] = $this->t('Provides a filter plugin that is in use in the following filter formats: %formats', ['%formats' => implode(', ', $used_in)]);
    }
  }
  return $reasons;
}
doc_Drupal
2016-10-29 09:14:53
Comments
Leave a Comment

Please login to continue.