You are here

protected function ReadinessRequirements::createRequirementForSeverity in Automatic Updates 8.2

Creates a requirement for checker results of a specific severity.

Parameters

int $severity: The severity for requirement. Should be one of the SystemManager::REQUIREMENT_* constants.

Return value

mixed[]|null Requirements array as specified by hook_requirements(), or NULL if no requirements can be determined.

1 call to ReadinessRequirements::createRequirementForSeverity()
ReadinessRequirements::getRequirements in src/Validation/ReadinessRequirements.php
Gets requirements arrays as specified in hook_requirements().

File

src/Validation/ReadinessRequirements.php, line 127

Class

ReadinessRequirements
Class for generating the readiness checkers' output for hook_requirements().

Namespace

Drupal\automatic_updates\Validation

Code

protected function createRequirementForSeverity(int $severity) : ?array {
  $severity_messages = [];
  $results = $this->readinessCheckerManager
    ->getResults($severity);
  if (!$results) {
    return NULL;
  }
  foreach ($results as $result) {
    $checker_messages = $result
      ->getMessages();
    if (count($checker_messages) === 1) {
      $severity_messages[] = [
        '#markup' => array_pop($checker_messages),
      ];
    }
    else {
      $severity_messages[] = [
        '#type' => 'details',
        '#title' => $result
          ->getSummary(),
        '#open' => FALSE,
        'messages' => [
          '#theme' => 'item_list',
          '#items' => $checker_messages,
        ],
      ];
    }
  }
  $requirement = [
    'title' => $this
      ->t('Update readiness checks'),
    'severity' => $severity,
    'value' => $this
      ->getFailureMessageForSeverity($severity),
    'description' => [
      'messages' => $severity_messages,
    ],
  ];
  if ($run_link = $this
    ->createRunLink()) {
    $requirement['description']['run_link'] = [
      '#type' => 'container',
      '#markup' => $run_link,
    ];
  }
  return $requirement;
}