function template_preprocess_update_report

Same name in other branches
  1. 9 core/modules/update/update.report.inc \template_preprocess_update_report()
  2. 8.9.x core/modules/update/update.report.inc \template_preprocess_update_report()
  3. 10 core/modules/update/update.report.inc \template_preprocess_update_report()

Prepares variables for project status report templates.

Default template: update-report.html.twig.

Parameters

array $variables: An associative array containing:

  • data: An array of data about each project's status.
1 call to template_preprocess_update_report()
UpdateReportTest::testTemplatePreprocessUpdateReport in core/modules/update/tests/src/Kernel/UpdateReportTest.php
@dataProvider providerTemplatePreprocessUpdateReport

File

core/modules/update/update.report.inc, line 23

Code

function template_preprocess_update_report(&$variables) {
    $data = isset($variables['data']) && is_array($variables['data']) ? $variables['data'] : [];
    $last = \Drupal::state()->get('update.last_check', 0);
    $variables['last_checked'] = [
        '#theme' => 'update_last_check',
        '#last' => $last,
        // Attach the library to a variable that gets printed always.
'#attached' => [
            'library' => [
                'update/drupal.update.admin',
            ],
        ],
    ];
    // For no project update data, populate no data message.
    if (empty($data)) {
        $variables['no_updates_message'] = _update_no_data();
    }
    $rows = [];
    foreach ($data as $project) {
        $project_status = [
            '#theme' => 'update_project_status',
            '#project' => $project,
        ];
        // Build project rows.
        if (!isset($rows[$project['project_type']])) {
            $rows[$project['project_type']] = [
                '#type' => 'table',
                '#attributes' => [
                    'class' => [
                        'update',
                    ],
                ],
            ];
        }
        $row_key = !empty($project['title']) ? mb_strtolower($project['title']) : mb_strtolower($project['name']);
        // Add the project status row and details.
        $rows[$project['project_type']][$row_key]['status'] = $project_status;
        // Add project status class attribute to the table row.
        switch ($project['status']) {
            case UpdateManagerInterface::CURRENT:
                $rows[$project['project_type']][$row_key]['#attributes'] = [
                    'class' => [
                        'color-success',
                    ],
                ];
                break;
            case UpdateFetcherInterface::UNKNOWN:
            case UpdateFetcherInterface::FETCH_PENDING:
            case UpdateFetcherInterface::NOT_FETCHED:
            case UpdateManagerInterface::NOT_SECURE:
            case UpdateManagerInterface::REVOKED:
            case UpdateManagerInterface::NOT_SUPPORTED:
                $rows[$project['project_type']][$row_key]['#attributes'] = [
                    'class' => [
                        'color-error',
                    ],
                ];
                break;
            case UpdateFetcherInterface::NOT_CHECKED:
            case UpdateManagerInterface::NOT_CURRENT:
            default:
                $rows[$project['project_type']][$row_key]['#attributes'] = [
                    'class' => [
                        'color-warning',
                    ],
                ];
                break;
        }
    }
    $project_types = [
        'core' => t('Drupal core'),
        'module' => t('Modules'),
        'theme' => t('Themes'),
        'module-uninstalled' => t('Uninstalled modules'),
        'theme-uninstalled' => t('Uninstalled themes'),
    ];
    $variables['project_types'] = [];
    foreach ($project_types as $type_name => $type_label) {
        if (!empty($rows[$type_name])) {
            ksort($rows[$type_name]);
            $variables['project_types'][] = [
                'label' => $type_label,
                'table' => $rows[$type_name],
            ];
        }
    }
}

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