Hi there,
To start, i'm fairly new to D8 and have basic OO knowledge. I'm not feeling very confident with building custom code for D8 (yet) but i'm eager to learn.
Now to my question. I want to build a custom FormElement to use within a new form created with YAML form. Thus far i have tried creating my own FormElement Class in src/Element namespace while using YamlFormOptions as an example. Somehow i am unable to make this new element appear in the [Add element] popup.
I also found http://bit.ly/2e9dZ1L but that doesn't seem to work either.
Some pointers would be very much appreciated. Perhaps this support request could lead into some general documentation.
Comments
Comment #2
ericmulder1980 commentedComment #3
jrockowitz commentedAdding an element to the YAML Form module requires two plugins...
First, you need to create a render (form) element. Here are most of the elements that ship with core. https://api.drupal.org/api/drupal/namespace/Drupal%21Core%21Render%21Ele...
Second, you need to define a YamlFormElement plugin that integrates the render element with the YAML Form module.
Below is the Toggle (toggle) element's render element and plugin
A few concepts and tips...
'#type': toggleto'#type': yamlform_toggle. You may or may not want to use the YamlForm module's prefixing.BTW, what type of element are you looking to create?
Comment #4
ericmulder1980 commentedHi Jacob,
Thank you so much for taking the time to answer my question. This really helps me.
The project i am working on is best explained by comparing it to relationship tests you can find in magazines. You receive a set of questions (theses), one per page, where you need to pick one answer that best suits your situation. Every answer receives a fixed score so at the end of the survey you will have a high or low total score. Additional the questions need to be tagged with a group which makes it possible to get a total score for only a subset of questions. Based on this score i will need to implement some Rules actions to redirect a user to a specific node. I want to do this in Rules because the business logic can change over time.
It has some overlap with the Likert form element. The difference here is that i don't want people to choose a rating per question but i want to add a rating to the answer.
I will keep this issue updated with my progress for others to benefit from.
Comment #5
jrockowitz commentedThe YAML Form module does not have full Rules integration, especially for submitted data but you obviously know how to code so you should look into the YamlFormHandler plugin, which be used to manage all your custom business logic.
Comment #6
fenstratMoving to Webform queue, see #2827845: [roadmap] YAML Form 8.x-1.x to Webform 8.x-5.x.
Comment #7
jrockowitz commentedClosing this ticket. It is also worth noting you can also add custom properties to an element or alter an existing element.
@see #2830042: Custom Element Properties
Comment #8
AOUSDM commentedDid someone try this on Drupal 8? Is there any other operations needed?
Just adding the two snippets crashes the site. What am I missing?
Comment #9
unsettlingtrendIs #3 still considered to be the proper way to go about creating custom form elements? I just want to make sure it hasn't changed since the YAMLForm/Webform merger; I'm trying to follow your example but still can't get my element to show up.
I'm trying to make a new composite element, and I was looking at the WebformAdress classes for guidance; does it make sense to extend the WebformCompositBase classes to do this?
Comment #10
unsettlingtrendI found your code. :-) http://cgit.drupalcode.org/webform/tree/modules/webform_example_composite
I'm expecting this will help; going to leave this comment though for anyone else.