Add drupal:serialization as dependency

Created on 5 June 2025, 9 days ago

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.

πŸ› Bug report
Status

Active

Version

3.1

Component

Code

Created by

πŸ‡«πŸ‡·France mattlc

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

Merge Requests

Comments & Activities

  • Issue created by @mattlc
  • πŸ‡«πŸ‡·France mattlc

    added dependency. tested locally on drupal 11.

  • Pipeline finished with Success
    9 days ago
    Total: 706s
    #515315
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    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?

  • πŸ‡«πŸ‡·France mattlc

    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.

  • Pipeline finished with Canceled
    5 days ago
    Total: 174s
    #517780
  • πŸ‡«πŸ‡·France mattlc

    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.

  • Pipeline finished with Success
    5 days ago
    Total: 381s
    #517781
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    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

  • πŸ‡ΊπŸ‡ΈUnited States apmsooner
  • Pipeline finished with Canceled
    4 days ago
    Total: 227s
    #518466
  • πŸ‡«πŸ‡·France mattlc

    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).

  • Pipeline finished with Success
    4 days ago
    #518469
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

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

Production build 0.71.5 2024