function template_preprocess_system_themes_page in Drupal 10
Same name and namespace in other branches
- 8 core/modules/system/system.admin.inc \template_preprocess_system_themes_page()
- 9 core/modules/system/system.admin.inc \template_preprocess_system_themes_page()
Prepares variables for appearance page templates.
Default template: system-themes-page.html.twig.
Parameters
$variables: An associative array containing:
- theme_groups: An associative array containing groups of themes.
- theme_group_titles: An associative array containing titles of themes.
File
- core/
modules/ system/ system.admin.inc, line 258 - Admin page callbacks for the system module.
Code
function template_preprocess_system_themes_page(&$variables) {
$groups = [];
$theme_groups = $variables['theme_groups'];
$variables['attributes']['id'] = 'system-themes-page';
foreach ($variables['theme_group_titles'] as $state => $title) {
if (!count($theme_groups[$state])) {
// Skip this group of themes if no theme is there.
continue;
}
// Start new theme group.
$theme_group = [];
$theme_group['state'] = $state;
$theme_group['title'] = $title;
$theme_group['themes'] = [];
$theme_group['attributes'] = new Attribute();
foreach ($theme_groups[$state] as $theme) {
$current_theme = [];
// Screenshot depicting the theme.
if ($theme->screenshot) {
$current_theme['screenshot'] = [
'#theme' => 'image',
'#uri' => $theme->screenshot['uri'],
'#alt' => $theme->screenshot['alt'],
'#title' => $theme->screenshot['title'],
'#attributes' => $theme->screenshot['attributes'],
];
}
else {
$current_theme['screenshot'] = [
'#theme' => 'image',
'#uri' => \Drupal::service('extension.list.module')
->getPath('system') . '/images/no_screenshot.png',
'#alt' => t('No screenshot'),
'#title' => t('No screenshot'),
'#attributes' => new Attribute([
'class' => [
'no-screenshot',
],
]),
];
}
// Localize the theme description.
$current_theme['description'] = t($theme->info['description']);
$current_theme['attributes'] = new Attribute();
$current_theme['name'] = $theme->info['name'];
$current_theme['version'] = $theme->info['version'] ?? '';
$current_theme['notes'] = $theme->notes;
$current_theme['is_default'] = $theme->is_default;
$current_theme['is_admin'] = $theme->is_admin;
$current_theme['module_dependencies'] = !empty($theme->module_dependencies_list) ? [
'#theme' => 'item_list',
'#items' => $theme->module_dependencies_list,
'#context' => [
'list_style' => 'comma-list',
],
] : [];
// Make sure to provide feedback on compatibility.
$current_theme['incompatible'] = '';
if (!empty($theme->info['core_incompatible'])) {
$current_theme['incompatible'] = t("This theme is not compatible with Drupal @core_version. Check that the .info.yml file contains a compatible 'core' or 'core_version_requirement' value.", [
'@core_version' => \Drupal::VERSION,
]);
}
elseif (!empty($theme->incompatible_region)) {
$current_theme['incompatible'] = t("This theme is missing a 'content' region.");
}
elseif (!empty($theme->incompatible_php)) {
if (substr_count($theme->info['php'], '.') < 2) {
$theme->info['php'] .= '.*';
}
$current_theme['incompatible'] = t('This theme requires PHP version @php_required and is incompatible with PHP version @php_version.', [
'@php_required' => $theme->info['php'],
'@php_version' => phpversion(),
]);
}
elseif (!empty($theme->incompatible_base)) {
$current_theme['incompatible'] = t('This theme requires the base theme @base_theme to operate correctly.', [
'@base_theme' => $theme->info['base theme'],
]);
}
elseif (!empty($theme->incompatible_engine)) {
$current_theme['incompatible'] = t('This theme requires the theme engine @theme_engine to operate correctly.', [
'@theme_engine' => $theme->info['engine'],
]);
}
elseif (!empty($theme->incompatible_module)) {
$current_theme['incompatible'] = t('This theme requires the listed modules to operate correctly.');
}
elseif (!empty($theme->module_dependencies_disabled)) {
if (!empty($theme->insufficient_module_permissions)) {
$current_theme['incompatible'] = t('This theme requires the listed modules to operate correctly. They must first be enabled by a user with permissions to do so.');
}
else {
$modules_url = (string) Url::fromRoute('system.modules_list')
->toString();
$current_theme['incompatible'] = t('This theme requires the listed modules to operate correctly. They must first be enabled via the <a href=":modules_url">Extend page</a>.', [
':modules_url' => $modules_url,
]);
}
}
// Build operation links.
$current_theme['operations'] = [
'#theme' => 'links',
'#links' => $theme->operations,
'#attributes' => [
'class' => [
'operations',
'clearfix',
],
],
];
$theme_group['themes'][] = $current_theme;
}
$groups[] = $theme_group;
}
$variables['theme_groups'] = $groups;
}