Fatal error when using unknown formatter

Created on 13 December 2024, 27 days ago

Problem/Motivation

When any of the components in a custom elements display has a formatter configured that cannot be found, a fatal error is thrown when building custom elements, and when visiting the UI to configure a CE display:

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "..." plugin does not exist. Valid plugin IDs for Drupal\custom_elements\CustomElementsFieldFormatterPluginManager are: [all found ones]

Steps to reproduce

On a development site,

  • Visit custom elements display edit screen
  • In a code editor, go to any formatter class that is used here (e.g. AutoCeFieldFormatter)
  • Edit the id = "VALUE" to be a strange value; save
  • Clear cache
  • Reload custom elements display edit screen

What would Core do

There's no error.

When editing a display, it shows the first value in the dropdown.

When rendering a node, it also takes that 'first' value to render the node.

This is because the EntityViewDisplay::getRenderer() -> FormatterPluginManager::getInstance() call has a fallback for unknown plugins (whereas our EntityCeDisplay::getRenderer() -> FormatterPluginManager::createInstance() does not).

Proposed resolution

Keep thowing fatal error during build/render: API output should not change silently.

Fix the form: a user should be able to fix the fatal error through the UI.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇳🇱Netherlands roderik Amsterdam,NL / Budapest,HU

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

Merge Requests

Comments & Activities

  • Issue created by @roderik
  • Merge request !107Fix fatal error for unknown formatter in UI → (Open) created by roderik
  • 🇳🇱Netherlands roderik Amsterdam,NL / Budapest,HU

    The proposed fix / MR does not provide a fatal error; it just shows a warning, but it still allows the user to save the form unmodified (so does not force correcting this mistake before saving).

    This happens to be the easiest, because I couldn't make form errors to work immediately. (I don't know if that's because of the table structure, tabledrag.js or whatever.)

    But also, I like it this way. If you have other things to change in this form, it's still possible to do those without affecting the missing formatter IDs, and fix things later (by e.g. enabling a missing module).

Production build 0.71.5 2024