How To Make A "line 42 of core/modules/system/src/Element/StatusReportPage.php" Error Go Away
tl;dr: Skip down to Fixing Ubercart
After installing Ubercart 7 on our eCommerce website, I started to see these errors in the Drupal 8 Administration GUI:
Hmmm. Let's have a look at the offending line of code, shall we?
// Loop through requirements and pull out items.
foreach ($element['#requirements'] as $key => $requirement) {
switch ($key) {
case 'cron':
foreach ($requirement['description'] as &$description_elements) {
foreach ($description_elements as &$description_element) {
if (isset($description_element['#url']) && $description_element['#url']->getRouteName() == 'system.run_cron') {
$description_element['#attributes']['class'][] = 'button';
$description_element['#attributes']['class'][] = 'button--small';
$description_element['#attributes']['class'][] = 'button--primary';
$description_element['#attributes']['class'][] = 'system-status-general-info__run-cron';
}
}
}
// Intentional fall-through.
Well, Line 42 of StatusReportPage.php seems to want to know something about the $description_element members that result from stepping through the $requirements array, which seems to hold a description of something.
Fixing Ubercart:
Ultimately, this boiled down to a bug in Ubercart 7, and it's an easy fix once ferreted out.
Just add a single line of code to uc_store.install in the uc_store subdirectory of ubercart:
function uc_store_requirements($phase) {
$requirements = [];
if ($phase == 'runtime') {
$severities = [
'warning' => REQUIREMENT_WARNING,
'error' => REQUIREMENT_ERROR,
];
$results = \Drupal::moduleHandler()->invokeAll('uc_store_status');
foreach ($results as $status) {
$requirements[] = [
'severity' => isset($severities[$status['status']]) ? $severities[$status['status']] : NULL,
'title' => $status['title'],
'value' => $status['desc'],
'description' => [],
];
}
}
return $requirements;
}
Once that line of code was added, the error went away:
(my thanks to bjaxelson for a great clue as to the ultimate source of this error!)
No comments:
Post a Comment