Skip to content

Ensure Drupal 11.4 fonts API compatibility in dxpr_theme.libraries.yml #833

Description

@jjroelofs

Summary

Drupal core 11.4 introduced a fonts: key in libraries.yml for native font preloading (core issue #3366561, change record https://www.drupal.org/node/3585574). A user reported PHP warnings when running Drupal 11.4.1 with the DXPR suite, including a grep result showing fonts: entries in dxpr_theme.libraries.yml at lines 211 and 219.

The current 8.x branch does not contain any fonts: entries in dxpr_theme.libraries.yml, so the user's installation appears to have been modified (possibly to mirror the font preloading entries added to dxpr_builder in PR dxpr/dxpr_builder#4745).

This issue tracks two concerns:

  1. If fonts: entries are added to dxpr_theme in the future, they must use YAML mapping syntax (path: {preload: true}) rather than list syntax (- path). List syntax produces integer keys that cause "Undefined array key preload" errors in HtmlResponseAttachmentsProcessor. See dxpr/dxpr_builder#4775 for the equivalent fix in dxpr_builder.

  2. The existing custom font preloading code in features/sooper-fonts/fonts-theme-settings-controller.inc uses #attached['html_head'] to add preload link tags. This approach is independent of the fonts: API and should continue to work, but should be evaluated for potential migration to the core fonts API in a future release.

Steps to reproduce

  1. Install Drupal 11.4.1 with dxpr_theme
  2. Add fonts: entries using YAML list syntax to dxpr_theme.libraries.yml (e.g., fonts:\n - path/to/font.woff2)
  3. Clear caches and load any page

What is the current bug behavior?

PHP warning: Undefined array key "preload" in Drupal\Core\Render\HtmlResponseAttachmentsProcessor->processAttachments() (line 132).

What is the expected correct behavior?

No PHP warnings. Font entries should use the mapping syntax expected by Drupal 11.4:

fonts:
  path/to/font.woff2:
    preload: true

Relevant logs and/or screenshots

Error from user report:

Warning: Undefined array key "preload" in Drupal\Core\Render\HtmlResponseAttachmentsProcessor->processAttachments() (line 132 of core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php).

Possible fixes

If fonts: entries are needed, use mapping syntax with explicit preload flag. See dxpr/dxpr_builder#4776 for the equivalent fix pattern.

Metadata

Metadata

Assignees

No one assigned

    Labels

    8.xbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions