Problem/Motivation

The plugin system is great but there seems to be some magic sauce that is used to turn an elements #type attribute into something FAPI can render. I've got a custom element that extends WebformTermSelect and it's not rendering due to the fact that the #type doesn't get converted to "select" like the WebformTermSelect's does. Where does this happen?

Discovered the issue by debugging into template_preprocess_webform().

Proposed resolution

Doco under https://www.drupal.org/docs/8/modules/webform

Comments

acbramley created an issue. See original summary.

jrockowitz’s picture

@acbramley To create a Webform element, you need to define a (Form)Element plugin and then the WebformElement plugin.

For an API example

@see \Drupal\webform\Element\WebformTermSelect
@see \Drupal\webform\Plugin\WebformElement\WebformTermSelect

For a how to from Phil Norton presentation 'Webform and Drupal 8'
@see https://www.youtube.com/watch?v=xrWEizVqAR4&t=1333s
@see https://www.slideshare.net/philipnorton42/webform-and-drupal-8

BTW, how to create Webform elements definitely needs to be documented.

acbramley’s picture

@jrockowitz thanks a lot! I totally missed the Element plugin.

uh_loek’s picture

100% this. I've found the above mentioned slides by accident and was able to add a new element, but I can't for the love of god figure out how to add properties to my new element. Been clicking through the source for hours now.

Some proper documentation on how to add new elements and how to get them renderable. I wouldn't mind writing these docs!

Linked SO question

jrockowitz’s picture

@uh_loek Welcome to the Drupal Community

I wanted the say "Hello" and encourage you to learn more about...

Watch video about helping us help you

jrockowitz’s picture

Status: Active » Closed (outdated)

The latest dev release includes a example of a custom WebformElement.

@see #2893508: Add webform_example_composite.module