safedelete-1.0.0/modules/safedelete_menu_report/src/Controller/MenuReportController.php
modules/safedelete_menu_report/src/Controller/MenuReportController.php
<?php
namespace Drupal\safedelete_menu_report\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
class MenuReportController extends ControllerBase {
protected $helper;
public static function create(ContainerInterface $container) {
$instance = new static();
$instance->helper = $container->get('safedelete_menu_report.report_helper');
return $instance;
}
public function report(Request $request) {
$build = [
'#title' => $this->t('Safedelete Menu Report'),
];
$config = $this->config('safedelete_menu_report.settings');
$menus = $config->get('menus') ?: [];
if (empty($menus)) {
$link = Link::fromTextAndUrl($this->t('Safedelete settings'), Url::fromRoute('safedelete.settings'))->toString();
$build['notice'] = [
'#markup' => $this->t('No menus configured. Please configure menus in @link.', ['@link' => $link]),
];
return $build;
}
foreach ($menus as $menu_name) {
if (!$menu_name) {
continue;
}
$rows = $this->helper->buildReportRows($menu_name);
$build['table_' . $menu_name] = [
'#type' => 'table',
'#header' => [$this->t('Title'), $this->t('ID'), $this->t('Bundle'), $this->t('Status'), $this->t('Link')],
'#rows' => $rows,
'#empty' => $this->t('No matching items.'),
'#attached' => [
'library' => ['safedelete_menu_report/admin'],
],
'#prefix' => '<h3 style="margin-top:1.25rem;">' . $this->t('Menu: @menu', ['@menu' => $menu_name]) . '</h3>',
];
}
return $build;
}
}
