After updating to Drupal 8.8.0 (with JSONAPI Extras 3.13.0) I receive the following notice:

Notice: Undefined index: field_name in Drupal\jsonapi_extras\Normalizer\ResourceIdentifierNormalizer->normalize() (line 47 of /srv/bindings/5e4b18c156474972b1247154adc08a2b/code/web/modules/contrib/jsonapi_extras/src/Normalizer/ResourceIdentifierNormalizer.php) #0 /srv/bindings/5e4b18c156474972b1247154adc08a2b/code/web/core/includes/bootstrap.inc(596): _drupal_error_handler_real(8, 'Undefined index...', '/srv/bindings/5...', 47, Array) #1 /srv/bindings/5e4b18c156474972b1247154adc08a2b/code/web/modules/contrib/jsonapi_extras/src/Normalizer/ResourceIdentifierNormalizer.php(47): _drupal_error_handler(8, 'Undefined index...', '/srv/bindings/5...', 47, Array) #2 /srv/bindings/5e4b18c156474972b1247154adc08a2b/code/vendor/symfony/serializer/Serializer.php(143): Drupal\jsonapi_extras\Normalizer\ResourceIdentifierNormalizer->normalize(Object(Drupal\jsonapi\JsonApiResource\ResourceIdentifier), 'api_json', Array) #3 /srv/bindings/5e4b18c156474972b1247154adc08a2b/code/web/core/modules/jsonapi/src/Serializer/Serializer.php(62): Symfony\Component\Serializer\Serializer->normalize(Object(Drupal\jsonapi\JsonApiResource\ResourceIdentifier), 'api_json', Array) #4 /srv/bindings/5e4b18c156474972b1247154adc08a2b/code/web/core/modules/jsonapi/src/Normalizer/DataNormalizer.php(26): Drupal\jsonapi\Serializer\Serializer->normalize(Object(Drupal\jsonapi\JsonApiResource\ResourceIdentifier), 'api_json', Array) #5 [internal function]: Drupal\jsonapi\Normalizer\DataNormalizer->Drupal\jsonapi\Normalizer\{closure}(Object(Drupal\jsonapi\JsonApiResource\ResourceIdentifier)) #6 /srv/bindings/5e4b18c156474972b1247154adc08a2b/code/web/core/modules/jsonapi/src/Normalizer/DataNormalizer.php(27): array_map(Object(Closure), Array) #7 /srv/bindings/5e4b18c156474972b1247154adc08a2b/code/vendor/symfony/serializer/Serializer.php(143): Drupal\jsonapi\Normalizer\DataNormalizer->normalize(Object(Drupal\jsonapi\JsonApiResource\RelationshipData), 'api_json', Array) #8 /srv/bindings/5e4b18c156474972b1247154adc08a2b/code/web/core/modules/jsonapi/src/Serializer/Serializer.php(62): Symfony\Component\Serializer\Serializer->normalize(Object(Drupal\jsonapi\JsonApiResource\RelationshipData), 'api_json', Array) #9 /srv/bindings/5e4b18c156474972b1247154adc08a2b/code/web/core/modules/jsonapi/src/Normalizer/RelationshipNormalizer.php(26): Drupal\jsonapi\Serializer\Serializer->normalize(Object(Drupal\jsonapi\JsonApiResource\RelationshipData), 'api_json', Array) #10 /srv/bindings/5e4b18c156474972b1247154adc08a2b/code/vendor/symfony/serializer/Serializer.php(143): Drupal\jsonapi\Normalizer\RelationshipNormalizer->normalize(Object(Drupal\jsonapi\JsonApiResource\Relationship), 'api_json', Array) #11 /srv/bindings/5e4b18c156474972b1247154adc08a2b/code/web/core/modules/jsonapi/src/Serializer/Serializer.php(62): Symfony\Component\Serializer\Serializer->normalize(Object(Drupal\jsonapi\JsonApiResource\Relationship), 'api_json', Array) #12 /srv/bindings/5e4b18c156474972b1247154adc08a2b/code/web/core/modules/jsonapi/src/Normalizer/ResourceObjectNormalizer.php(187): Drupal\jsonapi\Serializer\Serializer->normalize(Object(Drupal\jsonapi\JsonApiResource\Relationship), 'api_json', Array) #13 /srv/bindings/5e4b18c156474972b1247154adc08a2b/code/web/core/modules/jsonapi/src/Normalizer/ResourceObjectNormalizer.php(121): Drupal\jsonapi\Normalizer\ResourceObjectNormalizer->serializeField(Object(Drupal\Core\Field\EntityReferenceFieldItemList), Array, 'api_json') #14 /srv/bindings/5e4b18c156474972b1247154adc08a2b/code/web/core/modules/jsonapi/src/Normalizer/ResourceObjectNormalizer.php(73): Drupal\jsonapi\Normalizer\ResourceObjectNormalizer->getNormalization(Array, Object(Drupal\jsonapi\JsonApiResource\ResourceObject), 'api_json', Array) #15 /srv/bindings/5e4b18c156474972b1247154adc08a2b/code/web/modules/contrib/jsonapi_extras/src/Normalizer/JsonApiNormalizerDecoratorBase.php(38): Drupal\jsonapi\Normalizer\ResourceObjectNormalizer->normalize(Object(Drupal\jsonapi\JsonApiResource\ResourceObject), 'api_json', Array) #16 /srv/bindings/5e4b18c156474972b1247154adc08a2b/code/web/modules/contrib/jsonapi_extras/src/Normalizer/ResourceObjectNormalizer.php(24): Drupal\jsonapi_extras\Normalizer\JsonApiNormalizerDecoratorBase->normalize(Object(Drupal\jsonapi\JsonApiResource\ResourceObject), 'api_json', Array) #17 /srv/bindings/5e4b18c156474972b1247154adc08a2b/code/vendor/symfony/serializer/Serializer.php(143): Drupal\jsonapi_extras\Normalizer\ResourceObjectNormalizer->normalize(Object(Drupal\jsonapi\JsonApiResource\ResourceObject), 'api_json', Array) #18 /srv/bindings/5e4b18c156474972b1247154adc08a2b/code/web/core/modules/jsonapi/src/Serializer/Serializer.php(62): Symfony\Component\Serializer\Serializer->normalize(Object(Drupal\jsonapi\JsonApiResource\ResourceObject), 'api_json', Array) #19 /srv/bindings/5e4b18c156474972b1247154adc08a2b/code/web/core/modules/jsonapi/src/Normalizer/DataNormalizer.php(26): Drupal\jsonapi\Serializer\Serializer->normalize(Object(Drupal\jsonapi\JsonApiResource\ResourceObject), 'api_json', Array) #20 [internal function]: Drupal\jsonapi\Normalizer\DataNormalizer->Drupal\jsonapi\Normalizer\{closure}(Object(Drupal\jsonapi\JsonApiResource\ResourceObject)) #21 /srv/bindings/5e4b18c156474972b1247154adc08a2b/code/web/core/modules/jsonapi/src/Normalizer/DataNormalizer.php(27): array_map(Object(Closure), Array) #22 /srv/bindings/5e4b18c156474972b1247154adc08a2b/code/vendor/symfony/serializer/Serializer.php(143): Drupal\jsonapi\Normalizer\DataNormalizer->normalize(Object(Drupal\jsonapi\JsonApiResource\ResourceObjectData), 'api_json', Array) #23

Patch to follow.

CommentFileSizeAuthor
#31 3101345-drupal-9.3-support.patch647 byteshari604
#24 3101345--field-name--24.patch4.08 KBe0ipso
#22 Notice-Undefined-variable-enhancer-3101345-21.patch1.69 KBtaras.suliatitskiy
#20 interdiff_19-20.txt1.15 KBdevoidfury
#20 Drupal-8.8.0-Notice-Undefined-index-field_name-3101345-20.patch1.67 KBdevoidfury
#19 3101345-19-check-empty-resource_object-before-calling-getResourceType.patch1.63 KBfranck_lorancy
#17 interdiff_13-17.txt1016 bytesdevoidfury
#17 Drupal-8.8.0-Notice-Undefined-index-field_name-3101345-17.patch1.29 KBdevoidfury
#13 Drupal-8.8.0-Notice-Undefined-index-field_name-3101345-13.patch1.21 KBjlockhart
#10 3101345-10.patch1.13 KBdmitry.korhov
#9 3101345-9.patch1.11 KBdmitry.korhov
#8 3101345-8.patch1.05 KBdmitry.korhov
#3 3101345-3.patch797 bytestaras.suliatitskiy
#2 3101345-2.patch937 bytesbriangonzalezmia
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

briangonzalezmia created an issue. See original summary.

briangonzalezmia’s picture

taras.suliatitskiy’s picture

3101345-3.patch
Just a small update to the module path to make it applicable.

briangonzalezmia’s picture

Thanks! @taras.suliatitskiy

Grimreaper’s picture

Status: Active » Needs review

Hello,

Thanks for the issue and the patch.

I think it is something that makes automated tests failure in the Entity share module: https://www.drupal.org/pift-ci-job/1511076

https://www.drupal.org/project/entity_share/issues/3101334

I will see if I can apply the patch for automated tests on drupal.org.

Grimreaper’s picture

I confirm that patch from comment 3 fixes the automated tests of Entity share module, Thanks!

I am still dealing with other deprecation notices.

markie’s picture

Status: Needs review » Needs work

While the patch does squash the error message, it does not resolve the overall problem. It appears that 'field_name' is never passed into context anymore, which means any enhancers added to an entity field will never get picked up. I am trying to add a custom field enhancer to an audio field, and I can never get the code to fire because the default normalized output is all that is returned. I have debugged both the media--audio entity and even just tried adding the enhancer to the audio field on the content type, but not one is the enhancer triggered. I put some watchdog notices in my code just to make sure. My custom fieldEnhancer was working previously, but one I upgraded to 8.8.1, and the core jsonapi, this is failing.

dmitry.korhov’s picture

Let's try to apply this patch.
$context['field_name'] was removed in JSON:API in Drupal 8.8.0 so we can not use it as a field identifier for Resource.

dmitry.korhov’s picture

Status: Needs review » Needs work

The last submitted patch, 10: 3101345-10.patch, failed testing. View results

dmitry.korhov’s picture

Status: Needs work » Needs review
jlockhart’s picture

Thanks for the work on this patch; really helped point me in the right direction. I did run into a couple of things when applying it.

1. I had an issue with instanceof and namespacing. My use case is for the Webforms module which extends EntityReferenceFieldItemList. So it wasn't returning true for their class. I've updated the check to include namespace.

2. This actually exposed another issue. IF there aren't any referenced entities, then the second check will throw an error. So I've added a check to make sure that there are entities before trying to match them.

With both of these updates this has resolved the issue of my webforms enhancer not working.

Status: Needs review » Needs work

The last submitted patch, 13: Drupal-8.8.0-Notice-Undefined-index-field_name-3101345-13.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

bachbach’s picture

hi,
patch #13 is working for me

Morbus Iff’s picture

Title: Drupal 8.8.0 - Notice: Undefined index: field_name » Drupal 8.8.x+ - Notice: Undefined index: field_name
Status: Needs work » Reviewed & tested by the community

Patch #13 is also working for me. Not sure about the test errors.

Bumping for maintainer look-see.

devoidfury’s picture

Patch #13 was mostly working for me, but it was throwing the following error sometimes in production:

Error: Call to a member function uuid() on null in docroot/modules/contrib/jsonapi_extras/src/Normalizer/ResourceIdentifierNormalizer.php on line 51
#0 vendor/symfony/serializer/Serializer.php(143): Drupal\jsonapi_extras\Normalizer\ResourceIdentifierNormalizer->normalize(Object(Drupal\jsonapi\JsonApiResource\ResourceIdentifier), 'api_json', Array)

I adjusted the patch to take into account NULL potentially being present in relatedEntities. If there's a better way to handle this let me know and I'll adjust the patch.

devoidfury’s picture

Status: Reviewed & tested by the community » Needs review
franck_lorancy’s picture

Thanks #17 works I had a condition to check if $context['resource_object'] is empty before calling getResourceType()
This refered to another issue : 3105165

devoidfury’s picture

Revised patch prevents `Undefined offset: 0` notices.

Status: Needs review » Needs work

The last submitted patch, 20: Drupal-8.8.0-Notice-Undefined-index-field_name-3101345-20.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

taras.suliatitskiy’s picture

Getting Notice: Undefined variable: enhancer in Drupal\jsonapi_extras\Normalizer\ResourceIdentifierNormalizer->normalize() (line 65 of /var/www/docroot/modules/contrib/jsonapi_extras/src/Normalizer/ResourceIdentifierNormalizer.php) with patch from #20. Added small sanity check to fix that.

szato’s picture

Status: Needs work » Needs review
e0ipso’s picture

I went with a different direction based on the patch here.

  • e0ipso committed 6b9dbaa on 8.x-3.x authored by dmitry.korhov
    Issue #3101345 by dmitry.korhov, devoidfury, taras.suliatitskiy,...
e0ipso’s picture

Status: Needs review » Fixed

Merged, as the failures are unrelated.

e0ipso’s picture

Thanks everyone involved in this issue. Free software maintainers need your contributions, and you didn't fail to deliver. ✨

vensires’s picture

@e0ipso that's one of the kindest comments I have read! Way to go sire :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

hari604’s picture

The previously shared patches were not working for me on Drupal 9.3.11.
Thus sharing this patch which has a minor change which exposes "field_name".

hari604’s picture

The previously shared patches were not working for me on Drupal 9.3.11.
Thus sharing this patch which has a minor change which exposes "field_name".

vensires’s picture

@hari604, this is marked as fixed and closed.

If you encountered it again, you should create a new issue, relate it to this one and set as affected version the latest 8.3-3.x release of this module.

hari604’s picture

@vensires
Sorry, I was not aware of that and though to post in this issue to get further resolution.
I have now created a new issue with another patch for D9.3.11 and 8.3-3.x release:
https://www.drupal.org/project/jsonapi_extras/issues/3280480