public static function WebformContentCreatorUtilities::getWebformElementsTypes in Webform Content Creator 3.x
Same name and namespace in other branches
- 8 src/WebformContentCreatorUtilities.php \Drupal\webform_content_creator\WebformContentCreatorUtilities::getWebformElementsTypes()
- 2.x src/WebformContentCreatorUtilities.php \Drupal\webform_content_creator\WebformContentCreatorUtilities::getWebformElementsTypes()
Return array with all webform elements types.
Parameters
mixed $webform_id: Webform id.
Return value
array Webform basic attributes and element types
2 calls to WebformContentCreatorUtilities::getWebformElementsTypes()
- FieldMappingBase::filterWebformFields in src/
Plugin/ FieldMappingBase.php - WebformContentCreatorManageFieldsForm::validateForm in src/
Form/ WebformContentCreatorManageFieldsForm.php - Form validation handler.
File
- src/
WebformContentCreatorUtilities.php, line 152
Class
- WebformContentCreatorUtilities
- Provides useful functions required in Webform content creator module.
Namespace
Drupal\webform_content_creatorCode
public static function getWebformElementsTypes($webform_id) {
if (!isset($webform_id) || empty($webform_id)) {
return NULL;
}
// Get webform entity.
$webform = \Drupal::entityTypeManager()
->getStorage(self::WEBFORM)
->load($webform_id);
if (empty($webform)) {
return NULL;
}
// Get webform submission storage.
$submission_storage = \Drupal::entityTypeManager()
->getStorage(self::WEBFORM_SUBMISSION);
$submission_storage_definitions = $submission_storage
->getFieldDefinitions();
if (empty($submission_storage_definitions)) {
return NULL;
}
// Get webform basic attributes definitions.
$result = $submission_storage
->checkFieldDefinitionAccess($webform, $submission_storage_definitions);
if (empty($result)) {
return NULL;
}
// Get webform elements and merge with the webform basic attributes.
$elements = $webform
->getElementsInitializedAndFlattened();
if (is_array($elements)) {
$webform_field_ids = array_keys($elements);
foreach ($webform_field_ids as $v) {
if (!isset($elements[$v]) || empty($elements[$v])) {
continue;
}
$result[$v] = $elements[$v]['#type'];
}
}
return $result;
}