You are here

public function DashboardController::dashboardAction in Devel 8

Same name and namespace in other branches
  1. 8.3 webprofiler/src/Controller/DashboardController.php \Drupal\webprofiler\Controller\DashboardController::dashboardAction()
  2. 8.2 webprofiler/src/Controller/DashboardController.php \Drupal\webprofiler\Controller\DashboardController::dashboardAction()
  3. 4.x webprofiler/src/Controller/DashboardController.php \Drupal\webprofiler\Controller\DashboardController::dashboardAction()

Generates the dashboard page.

Parameters

Profile $profile:

Return value

array

1 string reference to 'DashboardController::dashboardAction'
webprofiler.routing.yml in webprofiler/webprofiler.routing.yml
webprofiler/webprofiler.routing.yml

File

webprofiler/src/Controller/DashboardController.php, line 85

Class

DashboardController
Class DashboardController

Namespace

Drupal\webprofiler\Controller

Code

public function dashboardAction(Profile $profile) {
  $this->profiler
    ->disable();
  $templateManager = $this->templateManager;
  $templates = $templateManager
    ->getTemplates($profile);
  $panels = [];
  $libraries = [
    'webprofiler/dashboard',
  ];
  $drupalSettings = [
    'webprofiler' => [
      'token' => $profile
        ->getToken(),
      'ide_link' => $this
        ->config('webprofiler.config')
        ->get('ide_link'),
      'ide_link_remote' => $this
        ->config('webprofiler.config')
        ->get('ide_link_remote'),
      'ide_link_local' => $this
        ->config('webprofiler.config')
        ->get('ide_link_local'),
      'collectors' => [],
    ],
  ];
  foreach ($templates as $name => $template) {

    /** @var DrupalDataCollectorInterface $collector */
    $collector = $profile
      ->getCollector($name);
    if ($collector
      ->hasPanel()) {
      $rendered = $template
        ->renderBlock('panel', [
        'token' => $profile
          ->getToken(),
        'name' => $name,
      ]);
      $panels[] = [
        '#theme' => 'webprofiler_panel',
        '#panel' => $rendered,
      ];
      $drupalSettings['webprofiler']['collectors'][] = [
        'id' => $name,
        'name' => $name,
        'label' => $collector
          ->getTitle(),
        'summary' => $collector
          ->getPanelSummary(),
        'icon' => $collector
          ->getIcon(),
      ];
      $libraries = array_merge($libraries, $collector
        ->getLibraries());
      $drupalSettings['webprofiler'] += $collector
        ->getDrupalSettings();
    }
  }
  $build = [];
  $build['panels'] = [
    '#theme' => 'webprofiler_dashboard',
    '#profile' => $profile,
    '#panels' => $panels,
    '#spinner_path' => '/' . $this
      ->moduleHandler()
      ->getModule('webprofiler')
      ->getPath() . '/images/searching.gif',
    '#attached' => [
      'drupalSettings' => $drupalSettings,
      'library' => $libraries,
    ],
  ];
  return $build;
}