abstract class SiteAuditCheckBase in Site Audit 8.3
Base class for Site Audit Check plugins.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\site_audit\Plugin\SiteAuditCheckBase implements SiteAuditCheckInterface uses StringTranslationTrait
Expanded class hierarchy of SiteAuditCheckBase
56 files declare their use of SiteAuditCheckBase
- BestPracticesFast404.php in src/
Plugin/ SiteAuditCheck/ BestPracticesFast404.php - BestPracticesFolderStructure.php in src/
Plugin/ SiteAuditCheck/ BestPracticesFolderStructure.php - BestPracticesMultisite.php in src/
Plugin/ SiteAuditCheck/ BestPracticesMultisite.php - BestPracticesServices.php in src/
Plugin/ SiteAuditCheck/ BestPracticesServices.php - BestPracticesSettings.php in src/
Plugin/ SiteAuditCheck/ BestPracticesSettings.php
File
- src/
Plugin/ SiteAuditCheckBase.php, line 11
Namespace
Drupal\site_audit\PluginView source
abstract class SiteAuditCheckBase extends PluginBase implements SiteAuditCheckInterface {
use StringTranslationTrait;
const AUDIT_CHECK_SCORE_INFO = 3;
const AUDIT_CHECK_SCORE_PASS = 2;
const AUDIT_CHECK_SCORE_WARN = 1;
const AUDIT_CHECK_SCORE_FAIL = 0;
/**
* Quantifiable number associated with result on a scale of 0 to 2.
*
* @var int
*/
protected $score;
/**
* Names of checks that should not run as a result of this check.
*
* @var array
*/
protected $abort = [];
/**
* User has opted out of this check in configuration.
*
* @var bool
*/
protected $optOut = FALSE;
/**
* If set, will override the Report's percentage.
*
* @var int
*/
protected $percentOverride;
/**
* Use for passing data between checks within a report.
*
* @var array
*/
protected $registry;
/**
* Are we in a static context.
*
* @var bool
*/
protected $static = TRUE;
/**
* Options passed in for reports and checks.
*
* @var array
*/
protected $options = [];
/**
* Constructor.
*
* @param array $registry
* Aggregates data from each individual check.
* @param bool $opt_out
* If set, will not perform checks.
*/
public function __construct($configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
if (isset($configuration['options'])) {
$this->options = $configuration['options'];
}
$this->registry = $configuration['registry'];
if (isset($configuration['opt_out']) && !empty($configuration['opt_out'])) {
$this->optOut = TRUE;
$this->score = SiteAuditCheckBase::AUDIT_CHECK_SCORE_INFO;
}
$static = FALSE;
}
/**
* Determine the result message based on the score.
*
* @return string
* Human readable message for a given status.
*/
public function getResult() {
if ($this->optOut) {
return $this
->t('Opted-out in site configuration.');
}
switch ($this->score) {
case SiteAuditCheckBase::AUDIT_CHECK_SCORE_PASS:
return $this
->getResultPass();
case SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN:
return $this
->getResultWarn();
case SiteAuditCheckBase::AUDIT_CHECK_SCORE_INFO:
return $this
->getResultInfo();
default:
return $this
->getResultFail();
}
}
/**
* Get a human readable label for a score.
*
* @return string
* Pass, Recommendation and so forth.
*/
public function getScoreLabel() {
switch ($this->score) {
case SiteAuditCheckBase::AUDIT_CHECK_SCORE_PASS:
return $this
->t('Pass');
case SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN:
return $this
->t('Warning');
case SiteAuditCheckBase::AUDIT_CHECK_SCORE_INFO:
return $this
->t('Information');
default:
return $this
->t('Blocker');
}
}
/**
* Get the ID or machine name for the check.
*
* @return string
* The ID or machine name for the check.
*/
public function getId() {
return $this
->getPluginDefinition()['id'];
}
/**
* Get the label for the check that describes, high level what is happening.
*
* @return string
* Get the label for the check that describes, high level what is happening.
*/
public function getLabel() {
return $this
->getPluginDefinition()['name'];
}
/**
* Get a more verbose description of what is being checked.
*
* @return string
* A sentence describing the check; shown in detail mode.
*/
public function getDescription() {
return $this
->getPluginDefinition()['description'];
}
/**
* Get the description of what happened in a failed check.
*
* @return string
* Something is explicitly wrong and requires action.
*/
public abstract function getResultFail();
/**
* Get the result of a purely informational check.
*
* @return string
* Purely informational response.
*/
public abstract function getResultInfo();
/**
* Get a description of what happened in a passed check.
*
* @return string
* Success; good job.
*/
public abstract function getResultPass();
/**
* Get a description of what happened in a warning check.
*
* @return string
* Something is wrong, but not horribly so.
*/
public abstract function getResultWarn();
/**
* Get action items for a user to perform if the check did not pass.
*
* @return string
* Actionable tasks to perform.
*/
public abstract function getAction();
/**
* Display action items for a user to perform.
*
* @return string
* Actionable tasks to perform, or nothing if check is opted-out.
*/
public function renderAction() {
if ($this->optOut) {
return '';
}
return $this
->getAction();
}
/**
* Calculate the score.
*
* @return int
* Constants indicating pass, fail and so forth.
*/
public abstract function calculateScore();
/**
* Get a quantifiable number representing a check result; lazy initialization.
*
* @return int
* Constants indicating pass, fail and so forth.
*/
public function getScore() {
if (!isset($this->score)) {
$this->score = $this
->calculateScore();
}
return $this->score;
}
/**
* Get the check registry.
*
* @return array
* Contains values calculated from this check and any prior checks.
*/
public function getRegistry() {
return $this->registry;
}
/**
* Determine whether the check failed so badly that the report must stop.
*
* @return bool
* Whether to stop the abort after this check.
*/
public function shouldAbort() {
return $this->abort;
}
/**
* Get the report percent override, if any.
*
* @return int
* The overridden percentage.
*/
public function getPercentOverride() {
return $this->percentOverride;
}
/**
* Invoke another check's calculateScore() method if it is needed.
*/
protected function checkInvokeCalculateScore($plugin_id) {
$checkManager = \Drupal::service('plugin.manager.site_audit_check');
if (isset($opt_out)) {
$check = $checkManager
->createInstance($plugin_id, [
'registry' => $this->registry,
'opt_out' => $opt_out,
]);
$check
->calculateScore();
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
SiteAuditCheckBase:: |
protected | property | Names of checks that should not run as a result of this check. | |
SiteAuditCheckBase:: |
protected | property | Options passed in for reports and checks. | |
SiteAuditCheckBase:: |
protected | property | User has opted out of this check in configuration. | |
SiteAuditCheckBase:: |
protected | property | If set, will override the Report's percentage. | |
SiteAuditCheckBase:: |
protected | property | Use for passing data between checks within a report. | |
SiteAuditCheckBase:: |
protected | property | Quantifiable number associated with result on a scale of 0 to 2. | |
SiteAuditCheckBase:: |
protected | property | Are we in a static context. | |
SiteAuditCheckBase:: |
constant | |||
SiteAuditCheckBase:: |
constant | |||
SiteAuditCheckBase:: |
constant | |||
SiteAuditCheckBase:: |
constant | |||
SiteAuditCheckBase:: |
abstract public | function | Calculate the score. | 54 |
SiteAuditCheckBase:: |
protected | function | Invoke another check's calculateScore() method if it is needed. | |
SiteAuditCheckBase:: |
abstract public | function | Get action items for a user to perform if the check did not pass. | 54 |
SiteAuditCheckBase:: |
public | function | Get a more verbose description of what is being checked. | |
SiteAuditCheckBase:: |
public | function | Get the ID or machine name for the check. | |
SiteAuditCheckBase:: |
public | function | Get the label for the check that describes, high level what is happening. | |
SiteAuditCheckBase:: |
public | function | Get the report percent override, if any. | |
SiteAuditCheckBase:: |
public | function | Get the check registry. | |
SiteAuditCheckBase:: |
public | function | Determine the result message based on the score. | |
SiteAuditCheckBase:: |
abstract public | function | Get the description of what happened in a failed check. | 54 |
SiteAuditCheckBase:: |
abstract public | function | Get the result of a purely informational check. | 54 |
SiteAuditCheckBase:: |
abstract public | function | Get a description of what happened in a passed check. | 54 |
SiteAuditCheckBase:: |
abstract public | function | Get a description of what happened in a warning check. | 54 |
SiteAuditCheckBase:: |
public | function | Get a quantifiable number representing a check result; lazy initialization. | |
SiteAuditCheckBase:: |
public | function | Get a human readable label for a score. | |
SiteAuditCheckBase:: |
public | function | Display action items for a user to perform. | |
SiteAuditCheckBase:: |
public | function | Determine whether the check failed so badly that the report must stop. | |
SiteAuditCheckBase:: |
public | function |
Constructor. Overrides PluginBase:: |
|
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. |