public function InstallablePluginTrait::validate in Markdown 8.2
Validates the plugin requirements.
Parameters
bool $runtime: Flag indicating whether to validate runtime requirements.
Return value
bool TRUE if requirements are met, FALSE if requirement violations exist.
File
- src/
Annotation/ InstallablePluginTrait.php, line 212
Class
- InstallablePluginTrait
- Trait for adding installable plugin properties to annotations.
Namespace
Drupal\markdown\AnnotationCode
public function validate($runtime = FALSE) {
$library = $this
->getInstalledLibrary() ?: $this
->getPreferredLibrary();
if (!$library) {
$library = current($this->libraries) ?: $this;
}
// Validate requirements.
foreach ($library->requirements as $requirement) {
if ($requirement instanceof InstallableLibrary) {
$requirement = $requirement
->createObjectRequirement($this);
}
/** @var \Symfony\Component\Validator\ConstraintViolationListInterface $violations */
$violations = Error::suppress(function () use ($requirement) {
return $requirement
->validate();
});
if ($violations) {
foreach ($violations as $violation) {
$key = (string) $violation
->getMessage();
if (!isset($library->requirementViolations[$key])) {
$library->requirementViolations[$key] = $violation
->getMessage();
}
break 2;
}
}
}
// Validate runtime requirements.
if ($runtime) {
foreach ($library->runtimeRequirements as $requirement) {
/** @var \Symfony\Component\Validator\ConstraintViolationListInterface $violations */
$violations = Error::suppress(function () use ($requirement) {
return $requirement
->validate();
});
if ($violations) {
foreach ($violations as $violation) {
$key = (string) $violation
->getMessage();
if (!isset($library->requirementViolations[$key])) {
$library->requirementViolations[$key] = $violation
->getMessage();
}
break 2;
}
}
}
}
// Replace requirements and violations with the appropriate library.
$this->requirements = $library->requirements;
$this->runtimeRequirements = $library->runtimeRequirements;
$this->requirementViolations = $library->requirementViolations;
return empty($this->requirementViolations);
}