public FilterUninstallValidator::validate($module)
Determines the reasons a module can not be uninstalled.
Example implementation:
1 2 3 4 5 6 7 8 9 10 | 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 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 ; } |
Please login to continue.