I am attempting to add, to a webform, a custom setting within in the settings tab (either a third party setting or one in a custom block) that will be a drop down list of all the elements listed in the build tab. The intent is, based on the author's selection, that the selected element will be the one whose information is labeled as the main piece of information for our API.
(I had images of the "Settigns" page and the "Build" page but can't figure out how to add them)
The problem I'm having is three-fold:
1) How can I get access to the list of elements in the settings tab so the author can select a preexisting element?
2) How do I save the custom/third-party-settings?
3) How can I then use this setting value in a twig/php file to use in my code?
P.S.: Here's my php hook that added those settings:
/**
* Implements hook_webform_third_party_settings_form_alter().
*/
function MY_MODULE_webform_third_party_settings_form_alter(&$form, FormStateInterface $form_state) {
$webform = $form_state->getFormObject()->getEntity();
$options = [
'Email',
'Phone',
'Other Element'
];
// Add in third party block
$form['third_party_settings']['conversion_name'] = [
'#type' => 'select',
'#options' => $options,
'#title' => t('Conversion Name'),
'#default_value' => $webform->getThirdPartySetting('MY_MODULE', 'conversion_name'),
];
$form['third_party_settings']['conversion_type'] = [
'#type' => 'select',
'#options' => ['Lead Gen', 'Option 2', 'Option 3'],
'#title' => t('Conversion Type'),
'#default_value' => $webform->getThirdPartySetting('MY_MODULE', 'conversion_type'),
];
// Add in custom block
$form['wa_conversion'] = [
'#type' => 'details',
'#title' => t('WA Conversion Settings'),
'#open' => TRUE,
'#weight' => -1,
];
$form['wa_conversion']['conversion_name'] = [
'#type' => 'select',
'#options' => $options,
'#title' => t('Conversion Name'),
'#default_value' => $webform->getThirdPartySetting('MY_MODULE', 'conversion_name'),
];
$form['wa_conversion']['conversion_type'] = [
'#type' => 'select',
'#options' => ['Lead Gen', 'Option 2', 'Option 3'],
'#title' => t('Conversion Type'),
'#default_value' => $webform->getThirdPartySetting('MY_MODULE', 'conversion_type'),
];
}
Comments
(I had images of the
You can create a sandbox project and upload images to the project page. After that you can share links to images. Alternatively, you can try to upload images to some image hosting and share links to them.
Сould you explain your use case in business terms?
Business Terms
We have a JavaScript function on our website that we want to be called on specific forms and we want that JavaScript function to access certain data that a Drupal author can select. The data will be the value of one of the inputs listed on the Build page, and the data that the JavaScript function would access would be the input selected by the Drupal author on the Settings page.
You may look at the following
You may look at the following article "Webforms and integration with third party services".