function _system_advisories_requirements

Same name in other branches
  1. 10 core/modules/system/system.install \_system_advisories_requirements()
  2. 11.x core/modules/system/system.install \_system_advisories_requirements()

Display requirements from security advisories.

Parameters

array[] $requirements: The requirements array as specified in hook_requirements().

1 call to _system_advisories_requirements()
system_requirements in core/modules/system/system.install
Implements hook_requirements().

File

core/modules/system/system.install, line 1609

Code

function _system_advisories_requirements(array &$requirements) : void {
    if (!\Drupal::config('system.advisories')->get('enabled')) {
        return;
    }
    
    /** @var \Drupal\system\SecurityAdvisories\SecurityAdvisoriesFetcher $fetcher */
    $fetcher = \Drupal::service('system.sa_fetcher');
    try {
        $advisories = $fetcher->getSecurityAdvisories(TRUE, 5);
    } catch (TransferException $exception) {
        $requirements['system_advisories']['title'] = t('Critical security announcements');
        $requirements['system_advisories']['severity'] = REQUIREMENT_WARNING;
        $requirements['system_advisories']['description'] = [
            '#theme' => 'system_security_advisories_fetch_error_message',
        ];
        watchdog_exception('system', $exception, 'Failed to retrieve security advisory data.');
        return;
    }
    if (!empty($advisories)) {
        $advisory_links = [];
        $severity = REQUIREMENT_WARNING;
        foreach ($advisories as $advisory) {
            if (!$advisory->isPsa()) {
                $severity = REQUIREMENT_ERROR;
            }
            $advisory_links[] = new Link($advisory->getTitle(), Url::fromUri($advisory->getUrl()));
        }
        $requirements['system_advisories']['title'] = t('Critical security announcements');
        $requirements['system_advisories']['severity'] = $severity;
        $requirements['system_advisories']['description'] = [
            'list' => [
                '#theme' => 'item_list',
                '#items' => $advisory_links,
            ],
        ];
        if (\Drupal::moduleHandler()->moduleExists('help')) {
            $requirements['system_advisories']['description']['help_link'] = Link::createFromRoute('What are critical security announcements?', 'help.page', [
                'name' => 'system',
            ], [
                'fragment' => 'security-advisories',
            ])->toRenderable();
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.