5 * Code required only when rendering the available updates report.
8 use Drupal\Core\Template\Attribute;
12 * Prepares variables for project status report templates.
14 * Default template: update-report.html.twig.
16 * @param array $variables
17 * An associative array containing:
18 * - data: An array of data about each project's status.
20 function template_preprocess_update_report(&$variables) {
21 $data = $variables['data'];
23 $last = \Drupal::state()->get('update.last_check') ?: 0;
25 $variables['last_checked'] = [
26 '#theme' => 'update_last_check',
28 // Attach the library to a variable that gets printed always.
31 'update/drupal.update.admin',
36 // For no project update data, populate no data message.
38 $variables['no_updates_message'] = _update_no_data();
43 foreach ($data as $project) {
45 '#theme' => 'update_project_status',
46 '#project' => $project,
49 // Build project rows.
50 if (!isset($rows[$project['project_type']])) {
51 $rows[$project['project_type']] = [
53 '#attributes' => ['class' => ['update']],
56 $row_key = !empty($project['title']) ? mb_strtolower($project['title']) : mb_strtolower($project['name']);
58 // Add the project status row and details.
59 $rows[$project['project_type']][$row_key]['status'] = $project_status;
61 // Add project status class attribute to the table row.
62 switch ($project['status']) {
64 $rows[$project['project_type']][$row_key]['#attributes'] = ['class' => ['color-success']];
67 case UPDATE_FETCH_PENDING:
68 case UPDATE_NOT_FETCHED:
69 case UPDATE_NOT_SECURE:
71 case UPDATE_NOT_SUPPORTED:
72 $rows[$project['project_type']][$row_key]['#attributes'] = ['class' => ['color-error']];
74 case UPDATE_NOT_CHECKED:
75 case UPDATE_NOT_CURRENT:
77 $rows[$project['project_type']][$row_key]['#attributes'] = ['class' => ['color-warning']];
83 'core' => t('Drupal core'),
84 'module' => t('Modules'),
85 'theme' => t('Themes'),
86 'module-disabled' => t('Uninstalled modules'),
87 'theme-disabled' => t('Uninstalled themes'),
90 $variables['project_types'] = [];
91 foreach ($project_types as $type_name => $type_label) {
92 if (!empty($rows[$type_name])) {
93 ksort($rows[$type_name]);
94 $variables['project_types'][] = [
95 'label' => $type_label,
96 'table' => $rows[$type_name],
103 * Prepares variables for update project status templates.
105 * Default template: update-project-status.html.twig.
107 * @param array $variables
108 * An associative array containing:
109 * - project: An array of information about the project.
111 function template_preprocess_update_project_status(&$variables) {
112 // Storing by reference because we are sorting the project values.
113 $project = &$variables['project'];
115 // Set the project title and URL.
116 $variables['title'] = (isset($project['title'])) ? $project['title'] : $project['name'];
117 $variables['url'] = (isset($project['link'])) ? Url::fromUri($project['link'])->toString() : NULL;
119 $variables['install_type'] = $project['install_type'];
120 if ($project['install_type'] == 'dev' && !empty($project['datestamp'])) {
121 $variables['datestamp'] = format_date($project['datestamp'], 'custom', 'Y-M-d');
124 $variables['existing_version'] = $project['existing_version'];
126 $versions_inner = [];
127 $security_class = [];
129 if (isset($project['recommended'])) {
130 if ($project['status'] != UPDATE_CURRENT || $project['existing_version'] !== $project['recommended']) {
132 // First, figure out what to recommend.
133 // If there's only 1 security update and it has the same version we're
134 // recommending, give it the same CSS class as if it was recommended,
135 // but don't print out a separate "Recommended" line for this project.
136 if (!empty($project['security updates'])
137 && count($project['security updates']) == 1
138 && $project['security updates'][0]['version'] === $project['recommended']
140 $security_class[] = 'project-update__version--recommended';
141 $security_class[] = 'project-update__version---strong';
144 $version_class[] = 'project-update__version--recommended';
145 // Apply an extra class if we're displaying both a recommended
146 // version and anything else for an extra visual hint.
147 if ($project['recommended'] !== $project['latest_version']
148 || !empty($project['also'])
149 || ($project['install_type'] == 'dev'
150 && isset($project['dev_version'])
151 && $project['latest_version'] !== $project['dev_version']
152 && $project['recommended'] !== $project['dev_version'])
153 || (isset($project['security updates'][0])
154 && $project['recommended'] !== $project['security updates'][0])
156 $version_class[] = 'project-update__version--recommended-strong';
158 $versions_inner[] = [
159 '#theme' => 'update_version',
160 '#version' => $project['releases'][$project['recommended']],
161 '#title' => t('Recommended version:'),
162 '#attributes' => ['class' => $version_class],
166 // Now, print any security updates.
167 if (!empty($project['security updates'])) {
168 $security_class[] = 'version-security';
169 foreach ($project['security updates'] as $security_update) {
170 $versions_inner[] = [
171 '#theme' => 'update_version',
172 '#version' => $security_update,
173 '#title' => t('Security update:'),
174 '#attributes' => ['class' => $security_class],
180 if ($project['recommended'] !== $project['latest_version']) {
181 $versions_inner[] = [
182 '#theme' => 'update_version',
183 '#version' => $project['releases'][$project['latest_version']],
184 '#title' => t('Latest version:'),
185 '#attributes' => ['class' => ['version-latest']],
188 if ($project['install_type'] == 'dev'
189 && $project['status'] != UPDATE_CURRENT
190 && isset($project['dev_version'])
191 && $project['recommended'] !== $project['dev_version']) {
192 $versions_inner[] = [
193 '#theme' => 'update_version',
194 '#version' => $project['releases'][$project['dev_version']],
195 '#title' => t('Development version:'),
196 '#attributes' => ['class' => ['version-latest']],
201 if (isset($project['also'])) {
202 foreach ($project['also'] as $also) {
203 $versions_inner[] = [
204 '#theme' => 'update_version',
205 '#version' => $project['releases'][$also],
206 '#title' => t('Also available:'),
207 '#attributes' => ['class' => ['version-also-available']],
212 if (!empty($versions_inner)) {
213 $variables['versions'] = $versions_inner;
216 if (!empty($project['disabled'])) {
217 sort($project['disabled']);
218 $variables['disabled'] = $project['disabled'];
221 sort($project['includes']);
222 $variables['includes'] = $project['includes'];
224 $variables['extras'] = [];
225 if (!empty($project['extra'])) {
226 foreach ($project['extra'] as $value) {
228 $extra_item['attributes'] = new Attribute();
229 $extra_item['label'] = $value['label'];
230 $extra_item['data'] = [
232 '#markup' => $value['data'],
233 '#suffix' => '</em>',
235 $variables['extras'][] = $extra_item;
239 // Set the project status details.
240 $status_label = NULL;
241 switch ($project['status']) {
242 case UPDATE_NOT_SECURE:
243 $status_label = t('Security update required!');
246 $status_label = t('Revoked!');
248 case UPDATE_NOT_SUPPORTED:
249 $status_label = t('Not supported!');
251 case UPDATE_NOT_CURRENT:
252 $status_label = t('Update available');
255 $status_label = t('Up to date');
258 $variables['status']['label'] = $status_label;
259 $variables['status']['attributes'] = new Attribute();
260 $variables['status']['reason'] = (isset($project['reason'])) ? $project['reason'] : NULL;
262 switch ($project['status']) {
264 $uri = 'core/misc/icons/73b355/check.svg';
268 case UPDATE_FETCH_PENDING:
269 case UPDATE_NOT_FETCHED:
270 $uri = 'core/misc/icons/e29700/warning.svg';
271 $text = t('Warning');
273 case UPDATE_NOT_SECURE:
275 case UPDATE_NOT_SUPPORTED:
276 $uri = 'core/misc/icons/e32700/error.svg';
279 case UPDATE_NOT_CHECKED:
280 case UPDATE_NOT_CURRENT:
282 $uri = 'core/misc/icons/e29700/warning.svg';
283 $text = t('Warning');
287 $variables['status']['icon'] = [