You are here

public function DatabaseAggregatorSensorPlugin::calculateDependencies in Monitoring 8

Calculates dependencies for the configured plugin.

Dependencies are saved in the plugin's configuration entity and are used to determine configuration synchronization order. For example, if the plugin integrates with specific user roles, this method should return an array of dependencies listing the specified roles.

array(
  'entity' => array(
    'user.role.anonymous',
    'user.role.authenticated',
  ),
  'module' => array(
    'node',
    'user',
  ),
  'theme' => array(
    'seven',
  ),
);

Return value

array An array of dependencies grouped by type (module, theme, entity). For example:

Overrides SensorPluginBase::calculateDependencies

See also

\Drupal\Core\Config\Entity\ConfigDependencyManager

\Drupal\Core\Config\Entity\ConfigEntityInterface::getConfigDependencyName()

File

src/Plugin/monitoring/SensorPlugin/DatabaseAggregatorSensorPlugin.php, line 383
Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\DatabaseAggregatorSensorPlugin.

Class

DatabaseAggregatorSensorPlugin
Database aggregator able to query a single db table.

Namespace

Drupal\monitoring\Plugin\monitoring\SensorPlugin

Code

public function calculateDependencies() {
  parent::calculateDependencies();

  // There is no API to load a list of all tables, loop through all modules
  // with a hook_schema() hook and try to find the table.
  \Drupal::moduleHandler()
    ->loadAllIncludes('install');
  foreach (\Drupal::moduleHandler()
    ->getImplementations('schema') as $module) {
    $schema = drupal_get_module_schema($module, $this->sensorConfig
      ->getSetting('table'));
    if (isset($schema['module'])) {
      $this
        ->addDependency('module', $schema['module']);
      break;
    }
  }
  return $this->dependencies;
}