Error when displaying fields that use the edit_uuid formatter

Created on 10 June 2025, about 1 month ago

Problem/Motivation

A TypeError occurs when displaying fields that use the edit_uuid formatter. The error specifically states that the constructor of Drupal\edit_uuid\Plugin\Field\FieldFormatter\EditUuidFieldFormatter is expecting an instance of Drupal\Core\Session\AccountProxyInterface as its first argument, but it receives an array instead.

This prevents content pages from rendering correctly when a UUID field using this formatter is present, leading to a critical display error.

Full Error Message:

TypeError: Drupal\edit_uuid\Plugin\Field\FieldFormatter\EditUuidFieldFormatter::__construct(): Argument #1 ($currentUser) must be of type Drupal\Core\Session\AccountProxyInterface, array given, called in /project/app/modules/contrib/edit_uuid/src/Plugin/Field/FieldFormatter/EditUuidFieldFormatter.php on line 46 in Drupal\edit_uuid\Plugin\Field\FieldFormatter\EditUuidFieldFormatter->__construct() (line 34 of modules/contrib/edit_uuid/src/Plugin/Field/FieldFormatter/EditUuidFieldFormatter.php).

Steps to reproduce

  • Ensure the edit_uuid module is installed and enabled.
  • In Edit UUID configuration section, add a field of type UUID to any content type.
  • Configure the display settings for this content type to display the UUID field created.
  • Create or edit any content of this type that has the UUID field configured.
  • Attempt to view the content on its full display page.

Expected Behavior:
The content page should render successfully, and the UUID field should display its value without errors.

Current Behavior:
The page fails to load, and the described TypeError is thrown.

Proposed resolution

The root cause of this TypeError lies in the create() static method within the EditUuidFieldFormatter plugin. When Drupal instantiates a field formatter, the create() method is responsible for injecting dependencies into the constructor. The constructor of FormatterBase (which EditUuidFieldFormatter extends) has a specific signature that requires several arguments (plugin ID, plugin definition, field definition, settings, etc.) before any custom services are injected.

Currently, the create() method is passing the $configuration array as the first argument to new static(), which conflicts with the constructor's expectation of AccountProxyInterface for its first custom argument ($currentUser).

The proposed resolution is to call constructor's parent and adust the create() method to correctly extract and pass the standard formatter arguments before injecting the current_user service ($container->get('current_user')) as the final argument expected by the EditUuidFieldFormatter's constructor.

Affected file: /modules/contrib/edit_uuid/src/Plugin/Field/FieldFormatter/EditUuidFieldFormatter.php

🐛 Bug report
Status

Needs review

Version

3.0

Component

Code

Created by

🇫🇷France federiko_

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