You are here

public function DiagnosticsService::getPluginsEnabled in Purge 8.3

Retrieve the configured plugin_ids that the service will use.

Return value

string[] Array with the plugin_ids of the enabled plugins.

Overrides ServiceBase::getPluginsEnabled

File

src/Plugin/Purge/DiagnosticCheck/DiagnosticsService.php, line 146

Class

DiagnosticsService
Provides a service that interacts with diagnostic checks.

Namespace

Drupal\purge\Plugin\Purge\DiagnosticCheck

Code

public function getPluginsEnabled() {
  if (!is_null($this->pluginsEnabled)) {
    return $this->pluginsEnabled;
  }

  // We blindly load all diagnostic check plugins that we discovered, but not
  // when plugins put dependencies on either a queue or purger plugin. When
  // plugins do depend, we load 'purge.purgers' and/or 'purge.queue' and
  // carefully check if we should load them or not.
  $load = function ($needles, $haystack) {
    if (empty($needles)) {
      return TRUE;
    }
    foreach ($needles as $needle) {
      if (in_array($needle, $haystack)) {
        return TRUE;
      }
    }
    return FALSE;
  };
  $this->pluginsEnabled = [];
  foreach ($this
    ->getPlugins() as $plugin) {
    if (!empty($plugin['dependent_queue_plugins'])) {
      if (!$load($plugin['dependent_queue_plugins'], $this
        ->getQueue()
        ->getPluginsEnabled())) {
        continue;
      }
    }
    if (!empty($plugin['dependent_purger_plugins'])) {
      if (!$load($plugin['dependent_purger_plugins'], $this
        ->getPurgers()
        ->getPluginsEnabled())) {
        continue;
      }
    }
    $this->pluginsEnabled[] = $plugin['id'];
    $this
      ->getLogger()
      ->debug('loaded diagnostic check plugin @id', [
      '@id' => $plugin['id'],
    ]);
  }
  return $this->pluginsEnabled;
}