Problem/Motivation

Custom_field installed and works fine. I tried to install webprofiler and an error occured (maybe due du cache clearing) :

PHP Fatal error:  Uncaught Error: Class "Drupal\serialization\Normalizer\PrimitiveDataNormalizer" not found in /var/www/html/web/modules/contrib/custom_field/src/Normalizer/StringLongNormalizer.php:11

After installing serialization module, error disapeared.

Steps to reproduce

  • install the module on Drupal 11
  • create some custom fields and populate
  • composer install drupal/webprofiler
  • drush en webprofiler

Proposed resolution

Add drupal:serialization as a dependency of the module.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mattlc created an issue. See original summary.

mattlc’s picture

Assigned: mattlc » Unassigned
Status: Active » Needs review

added dependency. tested locally on drupal 11.

apmsooner’s picture

Status: Needs review » Postponed (maintainer needs more info)

Is there another alternative? I don't really want to put a dependency on serialization just to make this work with a contrib module that does not seem to even have that much usage. This seems like something that should be accounted for in the web profiler module IMO. Why would it even be conflicting with normalizers that have nothing to do with it?

mattlc’s picture

Actually, the dependency already exists for jsonapi integration in custom_field's code (in all the Normalizer classes).

Normalizers are used when jsonapi module is enabled. jsonapi requires serialization module so this is why the bug is quite "silent".

If you don't want this dependency to be in added to custom_field, one solution could be to move the jsonapi integration (EntityReferenceNormalizer, StringLongNormalizer, UriNormalizer and associated services definitions) to a submodule that depends on serialization core module.

mattlc’s picture

Status: Postponed (maintainer needs more info) » Needs review

Just updated the fix to extract dependency in a submodule.
Also taken care of auto-enable the submodule to keep consistency when jsonapi module is enabled.

apmsooner’s picture

This makes better sense I think. Just remove the serialization dependency from custom_field.info and change the dependency on custom_field_jsonapi.info to drupal/jsonapi since it already has the dependency for serialization.

Technically the keys in custom_field_jsonapi.services.yml should be changed to match the sub-module also.

e.g. custom_field_jsonapi.normalizer.string_long

apmsooner’s picture

Title: Add drupal:serialization as dependency » Move jsonapi normalizers into sub-module
Status: Needs review » Needs work
mattlc’s picture

Status: Needs work » Needs review

Implemented asked modifications.
Tested on Drupal 11 locally.
Should be tested on both Drupal 11 and Drupal 10.3+ especially with jsonapi enabled prior to update (to test auto-enable of submodule).

apmsooner’s picture

Awesome, thank you! I'll review and merge as soon as I get a chance and should plan to get into next release.

apmsooner’s picture

Status: Needs review » Fixed

This checks out fine on Drupal 10 for me. Nice work @mattic

  • apmsooner committed 5e31a48c on 3.1.x authored by mattlc
    Issue #3528633 by mattlc, apmsooner: Move jsonapi normalizers into sub-...
apmsooner’s picture

Status: Needs review » Fixed
apmsooner’s picture

Status: Fixed » Closed (fixed)