View source
<?php
namespace Drupal\unused_modules;
use Drupal\Core\Controller\ControllerBase;
class UnusedModulesController extends ControllerBase {
public function renderProjectsTable($filter) {
$helper = \Drupal::service('unused_modules.helper');
$modules = $helper
->getModulesByProject();
$header = [
'Project',
'Project has Enabled Modules',
'Project Path',
];
$rows = [];
foreach ($modules as $module) {
if ($filter === 'all') {
$rows[$module->projectName] = [
$module->projectName,
$module->projectHasEnabledModules ? $this
->t("Yes") : $this
->t("No"),
$module->projectPath,
];
}
elseif ($filter === 'disabled') {
if (!$module->projectHasEnabledModules) {
$rows[$module->projectName] = [
$module->projectName,
$module->projectHasEnabledModules ? $this
->t("Yes") : $this
->t("No"),
$module->projectPath,
];
}
}
}
if (!$rows) {
return [
'#type' => 'markup',
'#markup' => $this
->t("Hurray, no orphaned projects!"),
];
}
return [
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
];
}
public function renderModulesTable($filter) {
$helper = \Drupal::service('unused_modules.helper');
$modules = $helper
->getModulesByProject();
$header = [
'Project',
'Module',
'Module enabled',
'Project has Enabled Modules',
'Project Path',
];
$rows = [];
foreach ($modules as $module) {
if ($filter === 'all') {
$rows[$module
->getName()] = [
$module->projectName,
$module
->getName(),
$module->moduleIsEnabled ? $this
->t("Yes") : $this
->t("No"),
$module->projectHasEnabledModules ? $this
->t("Yes") : $this
->t("No"),
$module->projectPath,
];
}
elseif ($filter === 'disabled') {
if (!$module->projectHasEnabledModules) {
$rows[$module
->getName()] = [
$module->projectName,
$module
->getName(),
$module->moduleIsEnabled ? $this
->t("Yes") : $this
->t("No"),
$module->projectHasEnabledModules ? $this
->t("Yes") : $this
->t("No"),
$module->projectPath,
];
}
}
}
if (!$rows) {
return [
'#type' => 'markup',
'#markup' => $this
->t("Hurray, no orphaned modules!"),
];
}
return [
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
];
}
}