Custom field normalizers should define support for custom_field data types.

Created on 12 June 2024, 16 days ago
Updated 15 June 2024, 13 days ago

Problem/Motivation

On Drupal 9.5.11, custom_field module 2.0.3, jsonapi, and jsonapi_extras, when hitting an api endpoint for a taxonomy term, or really any entity, we are getting errors coming from the custom_field normalizers, which are being used where they shouldn't be, such as the string_long being used for integer data type since it is extending PrimitiveDataNormalizer with a higher priority. Here are the related errors:

Error: Call to undefined method Drupal\Core\TypedData\Plugin\DataType\IntegerData::getProcessed() in Drupal\custom_field\Normalizer\StringLongNormalizer->normalize() (line 20 of /var/www/html/web/modules/composer/custom_field/src/Normalizer/StringLongNormalizer.php)

AssertionError: assert($object instanceof CustomFieldUri) in assert() (line 51 of /var/www/html/web/modules/composer/custom_field/src/Normalizer/UriNormalizer.php)

Steps to reproduce

Install Drupal 9.5.11, custom field 2.0.3, jsonapi, jsonapi_extras, and hit taxonomy endpoint.

Proposed resolution

Restrict the custom_field normalizers with protected $supportedInterfaceOrClass

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mrconnerton

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

Merge Requests

Comments & Activities

  • Issue created by @mrconnerton
  • Status changed to Needs review 16 days ago
  • πŸ‡ΊπŸ‡ΈUnited States mrconnerton

    Created a MR for the basic update. Will continue testing locally, but initial errors have gone away and json:api results are returning properly now.

  • Pipeline finished with Success
    16 days ago
    Total: 437s
    #197449
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    Thanks for the patch. The EntityReferenceNormalizer however also supports CustomFieldImage so would either need to revise this to support both types or split that off into its own separate normalizer. Open to further review.

  • Status changed to Needs work 13 days ago
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    btw, i guess this is an oversight around Drupal 9 compatibility as those errors aren't happening in Drupal 10 because of this function:

    /**
       * {@inheritdoc}
       */
      public function getSupportedTypes(?string $format): array {
        return [
          CustomFieldEntityReference::class => TRUE,
          CustomFieldImage::class => TRUE,
        ];
      }
    
Production build 0.69.0 2024