Problem/Motivation

We have a few custom composite elements which extend the WebformCompositeBase class and specifically use the method preRenderCompositeFormElement. After updating the webform module to version 8.x-5.0-rc17 this method was not being called breaking existing functionality that previously worked.

I think the cause is the introduction of new trait WebformCompositeFormElementTrait and a new pre render method preRenderWebformCompositeFormElement.

Ideally would like some guidance on:
a.) if this is a bug i.e. the backwards compatibly does not work as expected,
b.) or if we should convert custom code to using the new above pre_render method
c.) if b, then do we need to include the WebformCompositeFormElementTrait in custom composite element classes that need to use the new pre_render method?

A good example where this is a an issue is the webform_craftyclicks module which extends the webformAddress class and uses the original pre render method preRenderCompositeFormElement. (Waiting to prove this in simplytest.me which is not loading currently)

Proposed resolution

I have some solutions which could work:

1.) In custom composite element classes define the original pre render in the gentInfo() method, but this did not seem to work for me, e.g.:

public function getInfo() {
    $info = parent::getInfo();
    $class = get_class($this);
    $info['#pre_render'] = [
      [$class, 'preRenderCompositeFormElement'],
    ];
    return $info;
  }

2.) In custom composite element classes include the new WebformCompositeFormElementTrait class and convert the pre render method to the new one preRenderWebformCompositeFormElement which seems to work.

3.) Patch webform core classes which extend WebformCompositeBase like webformAddress add the new pre render parent method, e.g.

public static function preRenderWebformCompositeFormElement($element) {
    return parent::preRenderWebformCompositeFormElement($element);
  }

Hopefully this is clear, second solution above is probably the easiest for us and can patch the webform_craftyclicks module but recommendations welcome.

Comments

benjas created an issue. See original summary.

benjas’s picture

Issue summary: View changes
jrockowitz’s picture

@benjas Thanks for catching this mistake. The regression was caused by #2982127: [accessibility] Wrap grouped and composite elements in a fieldset (includes composite, email confirm, password confirm).

I think 2) is the best approach and can you please help me out by writing a simple change record.

Replacing preRenderCompositeFormElement with preRenderWebformCompositeFormElement should work without any problems.

benjas’s picture

@jrockowitz, thanks for prompt reply. Added a draft change record here, please review and publish.

jrockowitz’s picture

Status: Active » Reviewed & tested by the community

I think that change record is fine. You should publish it and people can add comments as needed.

jrockowitz’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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