You are here

public function SensorManager::createInstance in Monitoring 8

Creates a pre-configured instance of a plugin.

Parameters

string $plugin_id: The ID of the plugin being instantiated.

array $configuration: An array of configuration relevant to the plugin instance.

Return value

object A fully configured plugin instance.

Throws

\Drupal\Component\Plugin\Exception\PluginException If the instance cannot be created, such as if the ID is invalid.

Overrides PluginManagerBase::createInstance

File

src/Sensor/SensorManager.php, line 85
Contains \Drupal\monitoring\Sensor\SensorManager.

Class

SensorManager
Manages sensor definitions and settings.

Namespace

Drupal\monitoring\Sensor

Code

public function createInstance($plugin_id, array $configuration = array()) {

  // Configuration contains SensorConfig object. Extracting
  // it to use for sensor object creation.
  $sensor_config = $configuration['sensor_config'];
  $definition = $this
    ->getDefinition($plugin_id);

  // SensorPlugin class from the sensor definition.

  /** @var \Drupal\monitoring\SensorPlugin\SensorPluginInterface $class */
  $class = $definition['class'];

  // Creating instance of the sensor. Refer SensorPlugin.php for arguments.
  return $class::create(\Drupal::getContainer(), $sensor_config, $plugin_id, $definition);
}