StatusReport.php

Same filename and directory in other branches
  1. 11.x core/lib/Drupal/Core/Render/Element/StatusReport.php
  2. 10 core/lib/Drupal/Core/Render/Element/StatusReport.php
  3. 9 core/lib/Drupal/Core/Render/Element/StatusReport.php
  4. 8.9.x core/lib/Drupal/Core/Render/Element/StatusReport.php

Namespace

Drupal\Core\Render\Element

File

core/lib/Drupal/Core/Render/Element/StatusReport.php

View source
<?php

namespace Drupal\Core\Render\Element;

use Drupal\Core\Extension\Requirement\RequirementSeverity;
use Drupal\Core\Render\Attribute\RenderElement;

/**
 * Creates status report page element.
 */
class StatusReport extends RenderElementBase {
  
  /**
   * {@inheritdoc}
   */
  public function getInfo() {
    return [
      '#theme' => 'status_report_grouped',
      '#priorities' => [
        'error',
        'warning',
        'checked',
        'ok',
      ],
      '#pre_render' => [
        [
          static::class,
          'preRenderGroupRequirements',
        ],
      ],
    ];
  }
  
  /**
   * Render API callback: Groups requirements.
   *
   * This function is assigned as a #pre_render callback.
   */
  public static function preRenderGroupRequirements($element) {
    $grouped_requirements = [];
    /** @var array{title: \Drupal\Core\StringTranslation\TranslatableMarkup, value: mixed, description: \Drupal\Core\StringTranslation\TranslatableMarkup, severity: \Drupal\Core\Extension\Requirement\RequirementSeverity} $requirement */
    foreach ($element['#requirements'] as $key => $requirement) {
      $severity = RequirementSeverity::Info;
      if (isset($requirement['severity'])) {
        $severity = $requirement['severity'] === RequirementSeverity::OK ? RequirementSeverity::Info : $requirement['severity'];
      }
      elseif (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'install') {
        $severity = RequirementSeverity::OK;
      }
      $grouped_requirements[$severity->status()]['title'] = $severity->title();
      $grouped_requirements[$severity->status()]['type'] = $severity->status();
      $grouped_requirements[$severity->status()]['items'][$key] = $requirement;
    }
    // Order the grouped requirements by a set order.
    $order = array_flip($element['#priorities']);
    uksort($grouped_requirements, function ($a, $b) use ($order) {
      return $order[$a] <=> $order[$b];
    });
    $element['#grouped_requirements'] = $grouped_requirements;
    return $element;
  }

}

Classes

Title Deprecated Summary
StatusReport Creates status report page element.

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