I'm trying to add a custom property (simple checkbox) to be admin controlled when editing a webform component, i.e. an extra setting for webform components. Using hook_form_builder_properties() to add the property works fine, as does adding it onto new custom webform components in _form_builder_webform_form_builder_map_CUSTOM_COMPONENT(). The property is displayed, mapped (to the serialized extra column) and saved correctly.
However when trying to add that same new property onto an existing webform component (not a custom component this time) saving just doesn't work. I've added the property onto other components in hook_form_builder_types_alter() and everything is fine apart from saving the value.
If I alter _form_builder_webform_property_map() to manually include the new property (and it's storage_parents) it saves fine. It appears _form_builder_webform_property_map() doesn't take into account the alterations to components made in fs_webform_form_builder_types_alter() and thus ignores custom/altered mappings.
Am I missing something simple here?
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 1569850-2-webform_property_map-d7.patch | 533 bytes | fenstrat |
Comments
Comment #1
quicksketchIndeed, this is the case. The _form_builder_webform_property_map() function is the source of information that is put into hook_form_builder_types(), not the other way around. I don't think modifying the types through hook_form_builder_types_alter() would have enough information to function properly. Perhaps we need a new hook for what you're trying to accomplish?
Comment #2
fenstratThanks for clearing that up @quicksketch.
How about this? Too simple?
It certainly achieves what I'm trying to do, i.e. add and save custom properties on webform components.
Comment #3
quicksketchSeems like that's the ticket, though I have to lament the length of our function names. My fault for "form_builder_webform_*" prefixing.
Comment #4
versantus.nik commentedI had exactly the same problem, and the patch works perfectly for me. Thanks @fenstrat
Comment #5
versantus.nik commentedhmm... I was a bit premature. With this patch the data is being saved correctly, but I can't figure out how to load it back, and so when I view the formbuilder edit screen by new property field is empty
My extra data is used in various components, but taking a "grid" as an example, the data is saved in the
$element['#webform_component']['extra']['mydata']field, but the only way I have found to retrieve it is to add in code into_form_builder_webform_form_builder_load_grid($element)function:Is there already hook I should be implementing to load this extra data in the right way?
Comment #6
versantus.nik commentedhmm... I was a bit premature. With this patch the data is being saved correctly, but I can't figure out how to load it back, and so when I view the formbuilder edit screen by new property field is empty
My extra data is used in various components, but taking a "grid" as an example, the data is saved in the
$element['#webform_component']['extra']['mydata']field, but the only way I have found to retrieve it is to add in code into_form_builder_webform_form_builder_load_grid($element)function:Is there already hook I should be implementing to load this extra data in the right way?
Comment #7
fenstrat@versantus have you implemented hook_form_builder_properties() to tell form builder about your form to edit your custom property?
In my implementation the
'#default_value' => $element['#prefilled']doesn't work with checkboxes, however it does for other fields. See how it goes for you.Comment #8
fenstratMarking RTBC as per #3.
Comment #9
quicksketchThanks @fenstrat! Committed in preparation for the 1.1 release. Appreciate your help!
Comment #10
fenstratMarvellous, thanks @quicksketch, great to see the 1.1 release.
p.s. Notice you're not using the Git attribution in your commits, something to consider as it's nice kickback for other contributors.
Comment #12
sk2013 commentedWe also facing the problem above.... We have a custom property which contains a check box.. The value of the check box is saved, but while editing the form the check box is unchecked...
Please, Any help would be grateful.
Comment #13
fenstrat@sk2013 I've also noticed issues with custom properties being reset when loaded for edit, but have not had any time to look further into it yet.
Could you please start a new issue here in the form_builder issue queue, add the details of how you can replicate the problem. If you link to it from here I'll look into it when I get a moment. Thanks.
Comment #14
sk2013 commentedWe have created a new issue for the custom property issue. The link is Custom properties being reset when loaded for edit