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
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().
Comments
Comment #2
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@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.
Comment #3
acbramley CreditAttribution: acbramley at PreviousNext for Transport for NSW commented@jrockowitz thanks a lot! I totally missed the Element plugin.
Comment #4
uh_loek CreditAttribution: uh_loek commented100% 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
Comment #5
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@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
Comment #6
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe latest dev release includes a example of a custom WebformElement.
@see #2893508: Add webform_example_composite.module