TwigDebugSensorPlugin.php in Monitoring 8
File
src/Plugin/monitoring/SensorPlugin/TwigDebugSensorPlugin.php
View source
<?php
namespace Drupal\monitoring\Plugin\monitoring\SensorPlugin;
use Drupal\monitoring\Entity\SensorConfig;
use Drupal\monitoring\Result\SensorResultInterface;
use Drupal\monitoring\SensorPlugin\SensorPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class TwigDebugSensorPlugin extends SensorPluginBase {
protected $container;
public function __construct(SensorConfig $sensor_config, $plugin_id, $plugin_definition, ContainerInterface $container) {
parent::__construct($sensor_config, $plugin_id, $plugin_definition, $container);
$this->container = $container;
}
public static function create(ContainerInterface $container, SensorConfig $sensor_config, $plugin_id, $plugin_definition) {
return new static($sensor_config, $plugin_id, $plugin_definition, $container);
}
public function runSensor(SensorResultInterface $result) {
$twig_config = $this->container
->getParameter('twig.config');
$result
->setStatus(SensorResultInterface::STATUS_OK);
if (!empty($twig_config['debug'])) {
$result
->setStatus(SensorResultInterface::STATUS_WARNING);
$result
->addStatusMessage('Twig debug mode is enabled');
}
if (isset($twig_config['cache']) && !$twig_config['cache']) {
$result
->setStatus(SensorResultInterface::STATUS_WARNING);
$result
->addStatusMessage('Twig cache disabled');
}
if (!empty($twig_config['auto_reload'])) {
$result
->setStatus(SensorResultInterface::STATUS_WARNING);
$result
->addStatusMessage('Automatic recompilation of Twig templates enabled');
}
$sensor_status = $result
->getStatus();
if ($sensor_status == SensorResultInterface::STATUS_OK) {
$result
->addStatusMessage('Optimal configuration');
}
}
}