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.
The signature is:
public function preCreate(array $values);
and should be:
public function preCreate(array &$values);
Accordingly, WebformHandlers cannot update the values in the preCreate method. Patch forthcoming.
Also, looking at the other methods, it's not clear to me if the intention of the xxxElement and xxxHandler are intended to be allowed to make changes to the new/updated element/handler, but currently they cannot. I have no opinion on the matter as they aren't part of my use case.
Comment | File | Size | Author |
---|---|---|---|
#5 | 3052518-5.patch | 4.07 KB | jrockowitz |
| |||
#4 | 3052518-4.patch | 3.41 KB | jrockowitz |
#2 | webform-precreate-3052518-2.patch | 2.25 KB | DanChadwick |
|
Comments
Comment #2
DanChadwick CreditAttribution: DanChadwick commentedComment #3
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThanks for catching that. For reference is the related API docs for ::preCreate
I have to find the history behind the xxxElement and xxxHandle methods.
Comment #4
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented\Drupal\webform\Plugin\WebformElementInterface::preCreate also needs to be updated.
The ::xxxElements methods are from #2879122: Create callback for question removal.
The ::xxxHandler methods are from #2865486: Adding, deleting, updating a Handler should trigger events and I did not document any use case. The methods could trigger a CRM to create a database table based on the current webform.
Comment #5
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedSo this change is going to cause a fatal error on any WebformElement of WebformHandler that extends the ::preCreate method. We need to also add a change notice.
Comment #6
DanChadwick CreditAttribution: DanChadwick commentedI didn't know preCreate was a standard Entity method, so I guess the element should change too. The impact of the change notice will be greatly mitigated by the fact no one has noticed this until now. It's too bad signature mismatches are a fatal error now.
I confirmed #5 applies and still allows handlers to change values.
Comment #8
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented