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.
Comment | File | Size | Author |
---|---|---|---|
#31 | 3101345-drupal-9.3-support.patch | 647 bytes | hari604 |
#24 | 3101345--field-name--24.patch | 4.08 KB | e0ipso |
#22 | Notice-Undefined-variable-enhancer-3101345-21.patch | 1.69 KB | taras.suliatitskiy |
#20 | interdiff_19-20.txt | 1.15 KB | devoidfury |
#20 | Drupal-8.8.0-Notice-Undefined-index-field_name-3101345-20.patch | 1.67 KB | devoidfury |
Comments
Comment #2
briangonzalezmiaComment #3
taras.suliatitskiy CreditAttribution: taras.suliatitskiy commented3101345-3.patch
Just a small update to the module path to make it applicable.
Comment #4
briangonzalezmiaThanks! @taras.suliatitskiy
Comment #5
GrimreaperHello,
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.
Comment #6
GrimreaperI confirm that patch from comment 3 fixes the automated tests of Entity share module, Thanks!
I am still dealing with other deprecation notices.
Comment #7
markie CreditAttribution: markie at Mediacurrent commentedWhile 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.
Comment #8
dmitry.korhovLet'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.Comment #9
dmitry.korhovComment #10
dmitry.korhovComment #12
dmitry.korhovComment #13
jlockhartThanks 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.
Comment #15
bachbach CreditAttribution: bachbach commentedhi,
patch #13 is working for me
Comment #16
Morbus IffPatch #13 is also working for me. Not sure about the test errors.
Bumping for maintainer look-see.
Comment #17
devoidfury CreditAttribution: devoidfury as a volunteer and at Mobomo commentedPatch #13 was mostly working for me, but it was throwing the following error sometimes in production:
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.
Comment #18
devoidfury CreditAttribution: devoidfury as a volunteer and at Mobomo commentedComment #19
franck_lorancy CreditAttribution: franck_lorancy commentedThanks #17 works I had a condition to check if $context['resource_object'] is empty before calling getResourceType()
This refered to another issue : 3105165
Comment #20
devoidfury CreditAttribution: devoidfury as a volunteer and at Mobomo commentedRevised patch prevents `Undefined offset: 0` notices.
Comment #22
taras.suliatitskiy CreditAttribution: taras.suliatitskiy at FFW for NBCUniversal commentedGetting
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.Comment #23
szato CreditAttribution: szato at Brainsum for Tieto commentedComment #24
e0ipsoI went with a different direction based on the patch here.
Comment #26
e0ipsoMerged, as the failures are unrelated.
Comment #27
e0ipsoThanks everyone involved in this issue. Free software maintainers need your contributions, and you didn't fail to deliver. ✨
Comment #28
vensires CreditAttribution: vensires commented@e0ipso that's one of the kindest comments I have read! Way to go sire :)
Comment #30
hari604 CreditAttribution: hari604 as a volunteer and at Appinfini commentedThe 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".
Comment #31
hari604 CreditAttribution: hari604 as a volunteer and at Appinfini commentedThe 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".
Comment #32
vensires CreditAttribution: vensires commented@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.
Comment #33
hari604 CreditAttribution: hari604 as a volunteer and at Appinfini commented@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