class ConfigValueSensorPlugin in Monitoring 8
Generic sensor that checks for a configuration value.
Plugin annotation
@SensorPlugin(
id = "config_value",
label = @Translation("Config Value"),
description = @Translation("Checks for a specific configuration value."),
addable = TRUE
)
Hierarchy
- class \Drupal\monitoring\SensorPlugin\SensorPluginBase implements SensorPluginInterface uses MessengerTrait, StringTranslationTrait
- class \Drupal\monitoring\SensorPlugin\ValueComparisonSensorPluginBase
- class \Drupal\monitoring\Plugin\monitoring\SensorPlugin\ConfigValueSensorPlugin uses DependencyTrait
- class \Drupal\monitoring\SensorPlugin\ValueComparisonSensorPluginBase
Expanded class hierarchy of ConfigValueSensorPlugin
File
- src/
Plugin/ monitoring/ SensorPlugin/ ConfigValueSensorPlugin.php, line 24 - Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\ConfigValueSensorPlugin
Namespace
Drupal\monitoring\Plugin\monitoring\SensorPluginView source
class ConfigValueSensorPlugin extends ValueComparisonSensorPluginBase {
use DependencyTrait;
/**
* {@inheritdoc}
*/
protected function getValueDescription() {
return t('The expected value of config %key, current value: %actVal', array(
'%key' => $this->sensorConfig
->getSetting('config') . ':' . $this->sensorConfig
->getSetting('key'),
'%actVal' => $this
->getValueText(),
));
}
/**
* {@inheritdoc}
*/
protected function getValue() {
$config = $this
->getConfig($this->sensorConfig
->getSetting('config'));
$key = $this->sensorConfig
->getSetting('key');
if (empty($key)) {
return NULL;
}
return $config
->get($key);
}
/**
* Gets config.
*
* @param string $name
* Config name.
*
* @return \Drupal\Core\Config\Config
* The config.
*/
protected function getConfig($name) {
// @todo fix condition $name==''
return $this
->getService('config.factory')
->get($name);
}
/**
* Adds UI for variables config object and key.
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
// Add weight to display config key before expected value.
$form['config'] = array(
'#type' => 'textfield',
'#default_value' => $this->sensorConfig
->getSetting('config') ? $this->sensorConfig
->getSetting('config') : '',
'#autocomplete_route_name' => 'monitoring.config_autocomplete',
'#maxlength' => 255,
'#title' => t('Config Object'),
'#required' => TRUE,
'#weight' => -1,
);
$form['key'] = array(
'#type' => 'textfield',
'#default_value' => $this->sensorConfig
->getSetting('key') ? $this->sensorConfig
->getSetting('key') : '',
'#maxlength' => 255,
'#title' => t('Key'),
'#required' => TRUE,
'#weight' => -1,
);
return $form;
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
$config_object = $this->sensorConfig
->getSetting('config');
$config = \Drupal::config($config_object);
if (isset($config) && isset($config
->getOriginal()['dependencies'])) {
$this
->addDependency('config', $config_object);
}
$this
->addDependency('module', strtok($config_object, '.'));
return $this->dependencies;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigValueSensorPlugin:: |
public | function |
Adds UI for variables config object and key. Overrides ValueComparisonSensorPluginBase:: |
|
ConfigValueSensorPlugin:: |
public | function |
Calculates dependencies for the configured plugin. Overrides SensorPluginBase:: |
|
ConfigValueSensorPlugin:: |
protected | function | Gets config. | |
ConfigValueSensorPlugin:: |
protected | function |
Gets the current value. Overrides ValueComparisonSensorPluginBase:: |
|
ConfigValueSensorPlugin:: |
protected | function |
Gets the value description that will be shown in the settings form. Overrides ValueComparisonSensorPluginBase:: |
|
DependencyTrait:: |
protected | property | The object's dependencies. | |
DependencyTrait:: |
protected | function | Adds multiple dependencies. | |
DependencyTrait:: |
protected | function | Adds a dependency. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
SensorPluginBase:: |
protected | property | Allows plugins to control if the value type can be configured. | 6 |
SensorPluginBase:: |
protected | property | The plugin implementation definition. | |
SensorPluginBase:: |
protected | property | The plugin_id. | |
SensorPluginBase:: |
protected | property | Current sensor config object. | |
SensorPluginBase:: |
protected | property | ||
SensorPluginBase:: |
public | function |
Service setter. Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public static | function |
Creates an instance of the sensor with config. Overrides SensorPluginInterface:: |
7 |
SensorPluginBase:: |
public | function |
Configurable value type. Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
Default configuration for a sensor. Overrides SensorPluginInterface:: |
8 |
SensorPluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
|
SensorPluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
SensorPluginBase:: |
public | function |
Gets sensor name (not the label). Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
@todo: Replace with injection Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
Determines if sensor is enabled. Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
3 |
SensorPluginBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
2 |
SensorPluginBase:: |
function | Instantiates a sensor object. | 8 | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
ValueComparisonSensorPluginBase:: |
protected | function | Gets the expected value. | |
ValueComparisonSensorPluginBase:: |
protected | function | Gets the current value as text. | |
ValueComparisonSensorPluginBase:: |
public | function |
Runs the sensor, updating $sensor_result. Overrides SensorPluginInterface:: |