I've been able to copy the example webform element, as detailed at Create webform element.

Although I've not tested submission yet, I think it's all looking good.

What would be great is if I could clone any of the standard webform elements.

I've made a copy of src/WeformElement/Email.php - and it appears in the list of webform elements available to be inserted into the webform - but when viewing the actual webform, it is not rendered.

It may be that I have to use the example webform element to create a new copy, and then change stuff in there to render an email field instead, but as mentioned I'd appreciate any pointers towards being able to clone any of the elements.

(The reason we need to clone them is due to styling. One text field might be used for a name, and another for a completely different purpose which will be styled differently, and as the cloned element has a new id then we can use the module Themable forms to provide more template suggestions.)

1 Answer 1


The WebformElement plugin acts as a wrapper around a Drupal Form element plugin. Therefore to actually create a webform element you need to define a Form element plugin with a corresponding Webform element plugin.

If you want to extend the Email element you need to extend the below classes

  • \Drupal\Core\Render\Element\Email
  • \Drupal\webform\Plugin\WebformElement\Email

All you might missing is a \Drupal\custom_module\Element\CustomModuleEmail class which probably will look something like...


namespace Drupal\custom_module\Element;

use Drupal\Core\Render\Element\Email;

 * @FormElement("custom_moduel_email")
class CustomModuleEmail extends Email { }
  • Thanks for the response - I'll try that on Monday. I was a bit puzzled because in the webform module the: src/Plugin/WebformElement/* files do not all seem to have equivalent src/Element/* classes in the webform module. From reading your reply I'm guessing that those Form elements are defined in core. Not able to check currently - will report back. Big thanks again - I feel I'm close to a really neat solution for the current requirements.
    – bailey86
    Commented Feb 3, 2018 at 13:17
  • Hmm.. I'm having difficulty with this - and how the class wrapping works. In the webform module there is /src/Plugin/WebformElement/Email.php but no corresponding Element/Email.php class being wrapped around. It would be great to know how to clone the existing webform elements - but for now I think I need to use the webform element example and modify that to suit. Cheers, Kev
    – bailey86
    Commented Feb 5, 2018 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.