Trying to add a custom form element type

Re: Trying to add a custom form element type

by Vitaly Potenko -
Number of replies: 0
Picture of Core developers Picture of Plugin developers
That's because the 'toHtml()' method isn't used by Moodle to render a QuickForm element actually. Moodle uses the Mustache templating engine to render the form elements from the time Mustache had been introduced to Moodle. Take a look at the 'text' element class which you're extending, you'll see that it implements the 'templatable' interface. Then, in formslib.php find the 'MoodleQuickForm_Renderer' class and it's method 'renderElement()'. In it's turn it calls the 'mform_element()' method of the core renderer. And it's where all the things happen, you'll see it from the source code.
By the way, it makes things a bit complicated when implementing a custom form element. The renderer looks for templates in core folder only by default and it's hardcoded. To add a custom template for your custom element you'll have to override this logic.