5 * Code required only when rendering the available updates report.
8 use Drupal\Component\Utility\Unicode;
9 use Drupal\Core\Template\Attribute;
13 * Prepares variables for project status report templates.
15 * Default template: update-report.html.twig.
17 * @param array $variables
18 * An associative array containing:
19 * - data: An array of data about each project's status.
21 function template_preprocess_update_report(&$variables) {
22 $data = $variables['data'];
24 $last = \Drupal::state()->get('update.last_check') ?: 0;
26 $variables['last_checked'] = [
27 '#theme' => 'update_last_check',
29 // Attach the library to a variable that gets printed always.
32 'update/drupal.update.admin',
37 // For no project update data, populate no data message.
39 $variables['no_updates_message'] = _update_no_data();
44 foreach ($data as $project) {
46 '#theme' => 'update_project_status',
47 '#project' => $project,
50 // Build project rows.
51 if (!isset($rows[$project['project_type']])) {
52 $rows[$project['project_type']] = [
54 '#attributes' => ['class' => ['update']],
57 $row_key = !empty($project['title']) ? Unicode::strtolower($project['title']) : Unicode::strtolower($project['name']);
59 // Add the project status row and details.
60 $rows[$project['project_type']][$row_key]['status'] = $project_status;
62 // Add project status class attribute to the table row.
63 switch ($project['status']) {
65 $rows[$project['project_type']][$row_key]['#attributes'] = ['class' => ['color-success']];
68 case UPDATE_FETCH_PENDING:
69 case UPDATE_NOT_FETCHED:
70 case UPDATE_NOT_SECURE:
72 case UPDATE_NOT_SUPPORTED:
73 $rows[$project['project_type']][$row_key]['#attributes'] = ['class' => ['color-error']];
75 case UPDATE_NOT_CHECKED:
76 case UPDATE_NOT_CURRENT:
78 $rows[$project['project_type']][$row_key]['#attributes'] = ['class' => ['color-warning']];
84 'core' => t('Drupal core'),
85 'module' => t('Modules'),
86 'theme' => t('Themes'),
87 'module-disabled' => t('Uninstalled modules'),
88 'theme-disabled' => t('Uninstalled themes'),
91 $variables['project_types'] = [];
92 foreach ($project_types as $type_name => $type_label) {
93 if (!empty($rows[$type_name])) {
94 ksort($rows[$type_name]);
95 $variables['project_types'][] = [
96 'label' => $type_label,
97 'table' => $rows[$type_name],
104 * Prepares variables for update project status templates.
106 * Default template: update-project-status.html.twig.
108 * @param array $variables
109 * An associative array containing:
110 * - project: An array of information about the project.
112 function template_preprocess_update_project_status(&$variables) {
113 // Storing by reference because we are sorting the project values.
114 $project = &$variables['project'];
116 // Set the project title and URL.
117 $variables['title'] = (isset($project['title'])) ? $project['title'] : $project['name'];
118 $variables['url'] = (isset($project['link'])) ? Url::fromUri($project['link'])->toString() : NULL;
120 $variables['install_type'] = $project['install_type'];
121 if ($project['install_type'] == 'dev' && !empty($project['datestamp'])) {
122 $variables['datestamp'] = format_date($project['datestamp'], 'custom', 'Y-M-d');
125 $variables['existing_version'] = $project['existing_version'];
127 $versions_inner = [];
128 $security_class = [];
130 if (isset($project['recommended'])) {
131 if ($project['status'] != UPDATE_CURRENT || $project['existing_version'] !== $project['recommended']) {
133 // First, figure out what to recommend.
134 // If there's only 1 security update and it has the same version we're
135 // recommending, give it the same CSS class as if it was recommended,
136 // but don't print out a separate "Recommended" line for this project.
137 if (!empty($project['security updates'])
138 && count($project['security updates']) == 1
139 && $project['security updates'][0]['version'] === $project['recommended']
141 $security_class[] = 'project-update__version--recommended';
142 $security_class[] = 'project-update__version---strong';
145 $version_class[] = 'project-update__version--recommended';
146 // Apply an extra class if we're displaying both a recommended
147 // version and anything else for an extra visual hint.
148 if ($project['recommended'] !== $project['latest_version']
149 || !empty($project['also'])
150 || ($project['install_type'] == 'dev'
151 && isset($project['dev_version'])
152 && $project['latest_version'] !== $project['dev_version']
153 && $project['recommended'] !== $project['dev_version'])
154 || (isset($project['security updates'][0])
155 && $project['recommended'] !== $project['security updates'][0])
157 $version_class[] = 'project-update__version--recommended-strong';
159 $versions_inner[] = [
160 '#theme' => 'update_version',
161 '#version' => $project['releases'][$project['recommended']],
162 '#title' => t('Recommended version:'),
163 '#attributes' => ['class' => $version_class],
167 // Now, print any security updates.
168 if (!empty($project['security updates'])) {
169 $security_class[] = 'version-security';
170 foreach ($project['security updates'] as $security_update) {
171 $versions_inner[] = [
172 '#theme' => 'update_version',
173 '#version' => $security_update,
174 '#title' => t('Security update:'),
175 '#attributes' => ['class' => $security_class],
181 if ($project['recommended'] !== $project['latest_version']) {
182 $versions_inner[] = [
183 '#theme' => 'update_version',
184 '#version' => $project['releases'][$project['latest_version']],
185 '#title' => t('Latest version:'),
186 '#attributes' => ['class' => ['version-latest']],
189 if ($project['install_type'] == 'dev'
190 && $project['status'] != UPDATE_CURRENT
191 && isset($project['dev_version'])
192 && $project['recommended'] !== $project['dev_version']) {
193 $versions_inner[] = [
194 '#theme' => 'update_version',
195 '#version' => $project['releases'][$project['dev_version']],
196 '#title' => t('Development version:'),
197 '#attributes' => ['class' => ['version-latest']],
202 if (isset($project['also'])) {
203 foreach ($project['also'] as $also) {
204 $versions_inner[] = [
205 '#theme' => 'update_version',
206 '#version' => $project['releases'][$also],
207 '#title' => t('Also available:'),
208 '#attributes' => ['class' => ['version-also-available']],
213 if (!empty($versions_inner)) {
214 $variables['versions'] = $versions_inner;
217 if (!empty($project['disabled'])) {
218 sort($project['disabled']);
219 $variables['disabled'] = $project['disabled'];
222 sort($project['includes']);
223 $variables['includes'] = $project['includes'];
225 $variables['extras'] = [];
226 if (!empty($project['extra'])) {
227 foreach ($project['extra'] as $value) {
229 $extra_item['attributes'] = new Attribute();
230 $extra_item['label'] = $value['label'];
231 $extra_item['data'] = [
233 '#markup' => $value['data'],
236 $variables['extras'][] = $extra_item;
240 // Set the project status details.
241 $status_label = NULL;
242 switch ($project['status']) {
243 case UPDATE_NOT_SECURE:
244 $status_label = t('Security update required!');
247 $status_label = t('Revoked!');
249 case UPDATE_NOT_SUPPORTED:
250 $status_label = t('Not supported!');
252 case UPDATE_NOT_CURRENT:
253 $status_label = t('Update available');
256 $status_label = t('Up to date');
259 $variables['status']['label'] = $status_label;
260 $variables['status']['attributes'] = new Attribute();
261 $variables['status']['reason'] = (isset($project['reason'])) ? $project['reason'] : NULL;
263 switch ($project['status']) {
265 $uri = 'core/misc/icons/73b355/check.svg';
269 case UPDATE_FETCH_PENDING:
270 case UPDATE_NOT_FETCHED:
271 $uri = 'core/misc/icons/e29700/warning.svg';
272 $text = t('Warning');
274 case UPDATE_NOT_SECURE:
276 case UPDATE_NOT_SUPPORTED:
277 $uri = 'core/misc/icons/e32700/error.svg';
280 case UPDATE_NOT_CHECKED:
281 case UPDATE_NOT_CURRENT:
283 $uri = 'core/misc/icons/e29700/warning.svg';
284 $text = t('Warning');
288 $variables['status']['icon'] = [