public static function WebformContentCreatorUtilities::getWebformElements in Webform Content Creator 3.x
Same name and namespace in other branches
- 8 src/WebformContentCreatorUtilities.php \Drupal\webform_content_creator\WebformContentCreatorUtilities::getWebformElements()
- 2.x src/WebformContentCreatorUtilities.php \Drupal\webform_content_creator\WebformContentCreatorUtilities::getWebformElements()
Get webform elements and properties structured as a tree.
Parameters
string $webform_id: Webform id.
Return value
array Tree with webform elements and basic attributes.
3 calls to WebformContentCreatorUtilities::getWebformElements()
- FieldMappingBase::filterWebformFields in src/
Plugin/ FieldMappingBase.php - FieldMappingBase::getSupportedWebformFields in src/
Plugin/ FieldMappingBase.php - WebformContentCreatorManageFieldsForm::constructTable in src/
Form/ WebformContentCreatorManageFieldsForm.php - Constructs table with mapping between webform and content type.
File
- src/
WebformContentCreatorUtilities.php, line 123
Class
- WebformContentCreatorUtilities
- Provides useful functions required in Webform content creator module.
Namespace
Drupal\webform_content_creatorCode
public static function getWebformElements($webform_id) {
$webform = \Drupal::entityTypeManager()
->getStorage(self::WEBFORM)
->load($webform_id);
$options = [];
$submission_storage = \Drupal::entityTypeManager()
->getStorage(self::WEBFORM_SUBMISSION);
$field_definitions = $submission_storage
->checkFieldDefinitionAccess($webform, $submission_storage
->getFieldDefinitions());
// Basic webform properties (sid, token, serial number ..)
foreach ($field_definitions as $key => $field_definition) {
if (isset($field_definition['type']) && !empty($field_definition['type'])) {
$options['1,' . $key] = $field_definition['title'] . ' (' . $key . ') - ' . $field_definition['type'];
}
}
// Webform elements.
$elements = $webform
->getElementsInitializedAndFlattened();
// Webform elements organized in a structured tree.
$result = self::buildTree($elements);
// Join with basic webform properties.
$result[t('Webform properties')
->render()] = $options;
return $result;
}