Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
FieldItemList::preSave() calls the list's item's presave method, not the preSave method. Note the camelCase.
Proposed resolution
Simply switch the case of the method name to the correct form.
Comment | File | Size | Author |
---|---|---|---|
#1 | fielditemlist_presave-2284017-1.patch | 443 bytes | t0xicCode |
Comments
Comment #1
t0xicCode CreditAttribution: t0xicCode commentedComment #2
t0xicCode CreditAttribution: t0xicCode commentedComment #3
jhodgdonI think this is correct. Thanks! But it is scary that the tests passed without this. Wonder if preSave was tested for lists of items that had their own preSave methods? Apparently not... probably it needs a test?
Comment #4
t0xicCode CreditAttribution: t0xicCode commentedI'm unassign myself since I'm not too sure where to start with test writting.
Comment #5
lokapujyaWe have a test support module named "Field API Test". We could add a presave() to that and then somewhat copy the testDeterminingChanges() in NodeSaveTest. While looking into this, I also noticed that the "Node module tests" support module uses hooks. I wonder if it should be rerolled to override the FieldItemInterface methods (and if we extend the field support module in the same way, that it should use the interface too.
Comment #6
jhodgdonThe problem in this issue is that a method called "presave" is being called, not "preSave", on the field item class. So we need a plugin with a preSave() method, in order to test, and some way to verify that this method is called for each item in a list.
Comment #7
Berdirmethod calls in PHP are case insensitive. It is impossible to test this because there's no functional bug here.
Comment #8
alexpottCommitted eb2bfe7 and pushed to 8.x. Thanks!