DashboardController::build() should accept the interface, not the implementation

Created on 20 January 2025, 8 days ago

Problem/Motivation

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.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇦🇹Austria mvonfrie

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024