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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DanChadwick created an issue. See original summary.

DanChadwick’s picture

Status: Active » Needs review
FileSize
2.25 KB
jrockowitz’s picture

Thanks for catching that. For reference is the related API docs for ::preCreate

I have to find the history behind the xxxElement and xxxHandle methods.

jrockowitz’s picture

\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.

jrockowitz’s picture

So 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.

DanChadwick’s picture

Status: Needs review » Reviewed & tested by the community

I 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.

  • jrockowitz committed a84a0f2 on 8.x-5.x
    Issue #3052518 by jrockowitz, DanChadwick: WebformHandlerInterface::...
jrockowitz’s picture

Status: Reviewed & tested by the community » Fixed
Thank you for helping make the Webform module and our community a little better and stronger.

Status: Fixed » Closed (fixed)

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