Custom field normalizers should define support for custom_field data types.

Created on 12 June 2024, 6 months ago
Updated 19 September 2024, 3 months 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

Closed: won't fix

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 6 months 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
    6 months 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 6 months 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,
        ];
      }
    
  • Status changed to Closed: won't fix 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    This is only an issue in the 2.x version which I'm no longer supporting due to the extent of api changes between versions. If someone comes across this issue for 2.x... the attached patch should work for you but highly encourage updating your site to latest core and switching to the 3.x module cause its way more feature rich.

Production build 0.71.5 2024