abstract class ProdCheckBase in Production check & Production monitor 8
Base class for all the prod check plugins.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\prod_check\Plugin\ProdCheck\ProdCheckBase implements ConfigurableInterface, ContainerFactoryPluginInterface, PluginFormInterface, ProdCheckInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of ProdCheckBase
12 files declare their use of ProdCheckBase
- Contact.php in src/
Plugin/ ProdCheck/ Modules/ Contact.php - CssAggregated.php in src/
Plugin/ ProdCheck/ Performance/ CssAggregated.php - DbLog.php in src/
Plugin/ ProdCheck/ Server/ DbLog.php - ErrorReporting.php in src/
Plugin/ ProdCheck/ Settings/ ErrorReporting.php - JsAggregated.php in src/
Plugin/ ProdCheck/ Performance/ JsAggregated.php
File
- src/
Plugin/ ProdCheck/ ProdCheckBase.php, line 23
Namespace
Drupal\prod_check\Plugin\ProdCheckView source
abstract class ProdCheckBase extends PluginBase implements ContainerFactoryPluginInterface, ProdCheckInterface, ConfigurableInterface, PluginFormInterface {
/**
* The prod check processor plugin manager.
*
* @var \Drupal\prod_check\Plugin\ProdCheckProcessorInterface;
*/
protected $processor;
/**
* The redirect destination service.
*
* @var \Drupal\Core\Routing\RedirectDestinationInterface;
*/
protected $destination;
/**
* The link generator service.
*
* @var \Drupal\Core\Utility\LinkGeneratorInterface;
*/
protected $linkGenerator;
/**
* The config factory
*
* @var \Drupal\Core\Config\ConfigFactoryInterface;
*/
protected $configFactory;
/**
* The date formatter service
*
* @var \Drupal\Core\Datetime\DateFormatter;
*/
protected $dateFormatter;
/**
* The module handler service
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface;
*/
protected $moduleHandler;
/**
* Constructs a Drupal\Component\Plugin\PluginBase object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Routing\RedirectDestinationInterface $destination
* The redirect destination service
* @param \Drupal\Core\Utility\LinkGeneratorInterface $generator
* The link generator service
* @param \Drupal\Core\Config\ConfigFactoryInterface $factory
* The config factory service
* @param \Drupal\Core\Datetime\DateFormatter $formatter
* The date formatter service
* @param \Drupal\Core\Extension\ModuleHandlerInterface $handler
* The module handler service
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, RedirectDestinationInterface $destination, LinkGeneratorInterface $generator, ConfigFactoryInterface $factory, DateFormatter $formatter, ModuleHandlerInterface $handler) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
if (isset($configuration['processor'])) {
$this->processor = $configuration['processor'];
}
$this->destination = $destination;
$this->linkGenerator = $generator;
$this->configFactory = $factory;
$this->dateFormatter = $formatter;
$this->moduleHandler = $handler;
$this->configuration += $this
->defaultConfiguration();
$this
->init();
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('redirect.destination'), $container
->get('link_generator'), $container
->get('config.factory'), $container
->get('date.formatter'), $container
->get('module_handler'));
}
/**
* {@inheritdoc}
*/
public function init() {
// Do nothing in the base class
}
/**
* {@inheritdoc}
*/
public function title() {
$definition = $this
->getPluginDefinition();
return $definition['title'];
}
/**
* {@inheritdoc}
*/
public function category() {
$definition = $this
->getPluginDefinition();
return $definition['category'];
}
/**
* Sets the processor
*/
public function setProcessor($processor) {
$this->processor = $processor;
}
/**
* Helper function to generate generic 'settings OK' description.
*/
protected function generateDescription($title, $route_name, $text = 'Your %link settings are OK for production use.') {
$url = Url::fromRoute($route_name);
$url
->setOption('attributes', [
'title' => $title,
]);
$destination = \Drupal::destination()
->getAsArray();
$url
->setOption('query', $destination);
return $this
->t($text, $this
->generateLinkArray($title, $route_name));
}
/**
* Helper function to generate link array to pass to the t() function
*/
protected function generateLinkArray($title, $route_name, $fragment = NULL) {
$url = Url::fromRoute($route_name);
$url
->setOption('attributes', [
'title' => $title,
]);
$destination = $this->destination
->getAsArray();
$url
->setOption('query', $destination);
$url
->setAbsolute(TRUE);
return [
'%link' => $this->linkGenerator
->generate($title, $url),
];
}
/**
* {@inheritdoc}
*/
public function severity() {
switch ($this->configuration['severity']) {
case ProdCheck::REQUIREMENT_INFO:
return $this->processor
->info();
break;
case ProdCheck::REQUIREMENT_ERROR:
return $this->processor
->error();
break;
default:
return $this->processor
->warning();
break;
}
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'severity' => ProdCheck::REQUIREMENT_WARNING,
];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$options = [
ProdCheck::REQUIREMENT_INFO => 'Informational message',
ProdCheck::REQUIREMENT_WARNING => 'Warning message',
ProdCheck::REQUIREMENT_ERROR => 'Error message',
];
$form['severity'] = [
'#type' => 'select',
'#title' => t('Severity'),
'#default_value' => $this->configuration['severity'],
'#options' => $options,
'#required' => TRUE,
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['severity'] = $form_state
->getValue('severity');
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return $this->configuration;
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$this->configuration = $configuration;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
return [];
}
/**
* {@inheritdoc}
*/
public function data() {
return [];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
ProdCheckBase:: |
protected | property | The config factory | |
ProdCheckBase:: |
protected | property | The date formatter service | |
ProdCheckBase:: |
protected | property | The redirect destination service. | |
ProdCheckBase:: |
protected | property | The link generator service. | |
ProdCheckBase:: |
protected | property | The module handler service | 1 |
ProdCheckBase:: |
protected | property | The prod check processor plugin manager. | |
ProdCheckBase:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
3 |
ProdCheckBase:: |
public | function | ||
ProdCheckBase:: |
public | function |
Returns the title of the check Overrides ProdCheckInterface:: |
|
ProdCheckBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
1 |
ProdCheckBase:: |
public | function |
Returns the extra data of the check. Overrides ProdCheckInterface:: |
1 |
ProdCheckBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
3 |
ProdCheckBase:: |
protected | function | Helper function to generate generic 'settings OK' description. | |
ProdCheckBase:: |
protected | function | Helper function to generate link array to pass to the t() function | |
ProdCheckBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
ProdCheckBase:: |
public | function |
Initializes the check plugin. Overrides ProdCheckInterface:: |
11 |
ProdCheckBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
ProdCheckBase:: |
public | function | Sets the processor | |
ProdCheckBase:: |
public | function |
Defines the severity of the check. Overrides ProdCheckInterface:: |
2 |
ProdCheckBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
3 |
ProdCheckBase:: |
public | function |
Returns the title of the plugin. Overrides ProdCheckInterface:: |
|
ProdCheckBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
ProdCheckBase:: |
public | function |
Constructs a Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
1 |
ProdCheckInterface:: |
public | function | Returns the fail messages for the check | 12 |
ProdCheckInterface:: |
public | function | Calculates the state for the check. | 12 |
ProdCheckInterface:: |
public | function | Returns the success messages for the check. | 12 |
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. |