public function PackageController::page in Ludwig 8
Shows the status of all required packages.
Return value
array Returns a render array as expected by drupal_render().
1 string reference to 'PackageController::page'
File
- src/
Controller/ PackageController.php, line 94
Class
- PackageController
- Displays the Packages report.
Namespace
Drupal\ludwig\ControllerCode
public function page() {
// If requested, download the missing packages first.
if ($this->requestStack
->getCurrentRequest()->query
->get('missing') == 'download') {
$this
->download();
return new RedirectResponse(Url::fromRoute('ludwig.packages')
->toString());
}
$info = $this->moduleExtensionList
->getAllInstalledInfo();
$build = [];
$build['packages'] = [
'#theme' => 'table',
'#header' => [
'package' => $this
->t('Package'),
'paths' => $this
->t('Paths'),
'resource' => $this
->t('Resource'),
'version' => $this
->t('Version'),
'required_by' => $this
->t('Required by'),
'status' => $this
->t('Status'),
],
'#attributes' => [
'class' => [
'system-status-report',
],
],
];
$missing = 0;
foreach ($this->packageManager
->getPackages() as $package_name => $package) {
if ($package['installed'] === FALSE) {
$missing++;
}
$guide_link = 'https://www.drupal.org/docs/contributed-modules/ludwig/ludwig-errors-warnings-and-notices';
if (($package['resource'] == 'classmap' || $package['resource'] == 'files') && empty($package['disable_warnings'])) {
$package['description'] .= $this
->t('<br><strong>Warning! The @resource type libraries are not supported by Ludwig automatically. @read_more.</strong>', [
'@resource' => strtoupper($package['resource']),
'@read_more' => Link::fromTextAndUrl($this
->t('Read more'), Url::fromUri($guide_link))
->toString(),
]);
}
elseif ($package['resource'] == 'exclude-from-classmap' && empty($package['disable_warnings'])) {
$package['description'] .= $this
->t('<br><strong>Notice! The @resource property is not supported by Ludwig.</strong> Despite this notice, the library is loaded properly and the module should work nicely. @read_more.', [
'@resource' => strtoupper($package['resource']),
'@read_more' => Link::fromTextAndUrl($this
->t('Read more'), Url::fromUri($guide_link))
->toString(),
]);
}
elseif ($package['resource'] == 'target-dir' && empty($package['disable_warnings'])) {
$package['description'] .= $this
->t('<br><strong>Warning! The @resource property is not supported by Ludwig.</strong> This module may lack some functionality. @read_more.', [
'@resource' => strtoupper($package['resource']),
'@read_more' => Link::fromTextAndUrl($this
->t('Read more'), Url::fromUri($guide_link))
->toString(),
]);
}
elseif ($package['resource'] == 'inactive' && empty($package['disable_warnings'])) {
$package['description'] .= $this
->t('<br><strong>Notice! The INACTIVE library. @read_more.</strong>', [
'@read_more' => Link::fromTextAndUrl($this
->t('Read more'), Url::fromUri($guide_link))
->toString(),
]);
}
elseif (($package['resource'] == 'legacy' || $package['resource'] == 'unknown') && empty($package['disable_warnings'])) {
$package['description'] .= $this
->t('<br><strong>Warning! The @resource library type. Not supported by Ludwig. @read_more.</strong>', [
'@resource' => strtoupper($package['resource']),
'@read_more' => Link::fromTextAndUrl($this
->t('Read more'), Url::fromUri($guide_link))
->toString(),
]);
}
elseif (!$package['installed']) {
$package['description'] = $this
->t('@download the library and place it in @path', [
'@download' => Link::fromTextAndUrl($this
->t('Download'), Url::fromUri($package['download_url']))
->toString(),
'@path' => $package['path'],
]);
}
$package_column = [];
if (!empty($package['homepage'])) {
$package_column[] = [
'#type' => 'link',
'#title' => $package['name'],
'#url' => Url::fromUri($package['homepage']),
'#options' => [
'attributes' => [
'target' => '_blank',
],
],
];
}
else {
$package_column[] = [
'#plain_text' => $package['name'],
];
}
if (!empty($package['description'])) {
$package_column[] = [
'#prefix' => '<div class="description">',
'#markup' => $package['description'],
'#suffix' => '</div>',
];
}
$required_by = $package['provider'];
if (isset($info[$package['provider']])) {
$required_by = $info[$package['provider']]['name'];
}
$build['packages']['#rows'][$package_name] = [
'class' => $package['installed'] ? [] : [
'error',
],
'data' => [
'package' => [
'data' => $package_column,
],
'paths' => implode(', ', $package['paths']),
'resource' => $package['resource'],
'version' => $package['version'],
'required_by' => $required_by,
'status' => $package['installed'] ? $this
->t('Installed') : $this
->t('Missing'),
],
];
}
if (!empty($missing)) {
// There are some missing packages, so render the
// "Download all missing packages" clickable button.
$build['#markup'] = $this
->t('<div class="button"><a href="@packages-url">Download and unpack all missing packages (@missing)</a></div><div> </div>', [
'@packages-url' => Url::fromRoute('ludwig.packages')
->toString() . '?missing=download',
'@missing' => $missing,
]);
}
else {
// There are no missing packages. For the UX consistency
// purpose render the button again, but as disabled one.
$build['#markup'] = $this
->t('<div class="button is-disabled">Download and unpack missing packages (0)</div><div> </div>');
}
return $build;
}