- Issue created by @mvonfrie
- Merge request !54Use the DashboardInterface in the controller instead of the class → (Open) created by mvonfrie
The parameter accepted by Drupal\dashboard\Controller\DashboardController::build()
is the Dashboard class. This is problematic if you have the dashboard object typed as the interface and furthermore, it is not best practice.
For example the following code works but results in the PhpStan error
Parameter #1 $dashboard of method Drupal\dashboard\Controller\DashboardController::build() expects Drupal\dashboard\Entity\Dashboard|null, Drupal\dashboard\DashboardInterface given.
$dashboard = \Drupal::service('dashboard.manager')->getDefaultDashboard(\Drupal::currentUser());
if ($dashboard) {
return DashboardController::create(\Drupal::getContainer())->build($dashboard);
}
(For a customer I need a block which renders the default dashboard on /user
.)
DashboardManager::getDefaultDashboard()
returns ?DashboardInterface
while DashboardController::build()
requires ?Dashboard
.
Active
2.0
Code