function system_page_top

Same name in other branches
  1. 9 core/modules/system/system.module \system_page_top()
  2. 10 core/modules/system/system.module \system_page_top()

Implements hook_page_top().

File

core/modules/system/system.module, line 1114

Code

function system_page_top() {
    
    /** @var \Drupal\Core\Routing\AdminContext $admin_context */
    $admin_context = \Drupal::service('router.admin_context');
    if ($admin_context->isAdminRoute() && \Drupal::currentUser()->hasPermission('administer site configuration')) {
        $route_match = \Drupal::routeMatch();
        $route_name = $route_match->getRouteName();
        if ($route_name !== 'system.status' && \Drupal::config('system.advisories')->get('enabled')) {
            
            /** @var \Drupal\system\SecurityAdvisories\SecurityAdvisoriesFetcher $fetcher */
            $fetcher = \Drupal::service('system.sa_fetcher');
            $advisories = $fetcher->getSecurityAdvisories(FALSE);
            if ($advisories) {
                $messenger = \Drupal::messenger();
                $display_as_errors = FALSE;
                $links = [];
                foreach ($advisories as $advisory) {
                    // To ensure that all the advisory messages are grouped together on
                    // the page, they must all be warnings or all be errors. If any
                    // advisories are not public service announcements, then display all
                    // the messages as errors because security advisories already tied to
                    // a specific release are immediately actionable by upgrading to a
                    // secure version of a project.
                    $display_as_errors = $display_as_errors ? TRUE : !$advisory->isPsa();
                    $links[] = new Link($advisory->getTitle(), Url::fromUri($advisory->getUrl()));
                }
                foreach ($links as $link) {
                    $display_as_errors ? $messenger->addError($link) : $messenger->addWarning($link);
                }
                if (\Drupal::moduleHandler()->moduleExists('help')) {
                    $help_link = t('(<a href=":system-help">What are critical security announcements?</a>)', [
                        ':system-help' => Url::fromRoute('help.page', [
                            'name' => 'system',
                        ], [
                            'fragment' => 'security-advisories',
                        ])->toString(),
                    ]);
                    $display_as_errors ? $messenger->addError($help_link) : $messenger->addWarning($help_link);
                }
            }
        }
    }
}

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