Dashboard entity should support common entity hooks

Created on 20 January 2025, 8 days ago

Problem/Motivation

Even if the Dashboard is a config entity type, it should support the common entity hooks. For example I need to add some extra styling to the dashboards, no matter whether they are displayed with the admin theme (Gin) or the custom theme. Because of that I need to apply the extra styling via a module and libraries-extend only works for themes.

As the Dashboard entity doesn't support the hook_prepocess_HOOK() to attach a library with the custom styling, the only possibility which works is

/**
 * Implements hook_preprocess_HOOK().
 */
function mymodule_preprocess_container(array &$variables): void {
  $libraries = $variables['element']['#attached']['library'] ?? [];
  if (in_array('dashboard/dashboard', $libraries)) {
    // Note!
    // Adding a library to $variables['element']['#attached']['library'] doesn't work, only
    // to $variables['#attached']['library'].
    $variables['#attached']['library'][] = 'mymodule/dashboard';
  }
}

which is very strange and hacky as I have to preprocess the container, test it's element having the dashboard/dashboard library and if so attach my custom library. But to make it even weirder, I cannot attach my library to the container element as that already has been processed, but only on the container directly.

Maybe I could implement hook_page_attachments_alter() and attach my library there if the dashboard/dashboard is present. But that would make it even harder if I needed to attach it only to specific dashboards.

Proposed resolution

Implement the common hooks for the Dashboard entity type, such as hook_preprocess_HOOK() or hook_entity_view() (and related ones).

Feature request
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

Comments & Activities

Production build 0.71.5 2024