SensorPluginBase.php in Monitoring 8
File
src/SensorPlugin/SensorPluginBase.php
View source
<?php
namespace Drupal\monitoring\SensorPlugin;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerTrait;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\monitoring\Entity\SensorConfig;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class SensorPluginBase implements SensorPluginInterface {
use StringTranslationTrait;
use MessengerTrait;
protected $sensorConfig;
protected $services = array();
protected $pluginId;
protected $pluginDefinition;
protected $configurableValueType = TRUE;
function __construct(SensorConfig $sensor_config, $plugin_id, $plugin_definition) {
$this->pluginId = $plugin_id;
$this->pluginDefinition = $plugin_definition;
$this->sensorConfig = $sensor_config;
}
public function addService($id, $service) {
$this->services[$id] = $service;
}
public function getDefaultConfiguration() {
return array();
}
public function getConfigurableValueType() {
return $this->configurableValueType;
}
public function getService($id) {
return \Drupal::service($id);
}
public function getSensorId() {
return $this->sensorConfig
->id();
}
public function isEnabled() {
return (bool) $this->sensorConfig
->isEnabled();
}
public function getPluginId() {
return $this->pluginId;
}
public function getPluginDefinition() {
return $this->pluginDefinition;
}
public function calculateDependencies() {
return array();
}
public static function create(ContainerInterface $container, SensorConfig $sensor_config, $plugin_id, $plugin_definition) {
return new static($sensor_config, $plugin_id, $plugin_definition);
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return $form;
}
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
}
}
Classes
Name |
Description |
SensorPluginBase |
Abstract SensorPluginInterface implementation with common behaviour and will be extended by
sensor plugins. |