public function AdminForm::addEnabledElements in Webform CiviCRM Integration 8.5
Add enabled elements to the webform.
Parameters
array $enabled:
1 call to AdminForm::addEnabledElements()
- AdminForm::postProcess in src/
AdminForm.php - Submission handler, saves CiviCRM options for a Webform node
File
- src/
AdminForm.php, line 2012 - Webform CiviCRM module's admin form.
Class
- AdminForm
- @file Webform CiviCRM module's admin form.
Namespace
Drupal\webform_civicrmCode
public function addEnabledElements($enabled) {
$webform_element_manager = \Drupal::getContainer()
->get('plugin.manager.webform.element');
foreach ($enabled as $enabled_key => $enabled_element) {
if (!is_array($enabled_element)) {
// If this is a string, it is not a new element. However, this
// probably needs to be revisited.
continue;
}
// Webform uses YAML dump, which dies on FormattableMarkup.
$enabled_element = array_map([
$this,
'stringifyFormattableMarkup',
], $enabled_element);
$element_plugin = $webform_element_manager
->getElementInstance([
'#type' => $enabled_element['type'],
]);
$stub_form = [];
$stub_form_state = new FormState();
$stub_form_state
->set('default_properties', $element_plugin
->getDefaultProperties());
if (!isset($enabled_element['title']) && isset($enabled_element['name'])) {
$enabled_element['title'] = $enabled_element['name'];
}
unset($enabled_element['name']);
$stub_form_state
->setValues($enabled_element);
$properties = $element_plugin
->getConfigurationFormProperties($stub_form, $stub_form_state);
$parent_key = '';
if (isset($enabled_element['parent'])) {
$parent_key = $enabled_element['parent'];
}
$this->webform
->setElementProperties($enabled_key, $properties, $parent_key);
}
}