function ModuleInstaller::removeCacheBins

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Extension/ModuleInstaller.php \Drupal\Core\Extension\ModuleInstaller::removeCacheBins()
  2. 10 core/lib/Drupal/Core/Extension/ModuleInstaller.php \Drupal\Core\Extension\ModuleInstaller::removeCacheBins()
  3. 11.x core/lib/Drupal/Core/Extension/ModuleInstaller.php \Drupal\Core\Extension\ModuleInstaller::removeCacheBins()

Helper method for removing all cache bins registered by a given module.

Parameters

string $module: The name of the module for which to remove all registered cache bins.

1 call to ModuleInstaller::removeCacheBins()
ModuleInstaller::uninstall in core/lib/Drupal/Core/Extension/ModuleInstaller.php
Uninstalls a given list of modules.

File

core/lib/Drupal/Core/Extension/ModuleInstaller.php, line 568

Class

ModuleInstaller
Default implementation of the module installer.

Namespace

Drupal\Core\Extension

Code

protected function removeCacheBins($module) {
    $service_yaml_file = \Drupal::service('extension.list.module')->getPath($module) . "/{$module}.services.yml";
    if (!file_exists($service_yaml_file)) {
        return;
    }
    $definitions = Yaml::decode(file_get_contents($service_yaml_file));
    $cache_bin_services = array_filter($definitions['services'] ?? [], function ($definition) {
        $tags = $definition['tags'] ?? [];
        foreach ($tags as $tag) {
            if (isset($tag['name']) && $tag['name'] == 'cache.bin') {
                return TRUE;
            }
        }
        return FALSE;
    });
    foreach (array_keys($cache_bin_services) as $service_id) {
        $backend = $this->kernel
            ->getContainer()
            ->get($service_id);
        if ($backend instanceof CacheBackendInterface) {
            $backend->removeBin();
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.