public static function WebformContentCreatorUtilities::getWebformElementsTypes in Webform Content Creator 8
Same name and namespace in other branches
- 3.x 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
1 call to WebformContentCreatorUtilities::getWebformElementsTypes()
- 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.
$submissionStorage = \Drupal::entityTypeManager()
->getStorage(self::WEBFORM_SUBMISSION);
$submissionStorageDefinitions = $submissionStorage
->getFieldDefinitions();
if (empty($submissionStorageDefinitions)) {
return NULL;
}
// Get webform basic attributes definitions.
$fieldDefinitions = $submissionStorage
->checkFieldDefinitionAccess($webform, $submissionStorageDefinitions);
if (empty($fieldDefinitions)) {
return NULL;
}
// Get webform elements and merge with the webform basic attributes.
$elements = $webform
->getElementsInitializedAndFlattened();
if (is_array($elements)) {
$webformFieldIds = array_keys($elements);
foreach ($webformFieldIds as $v) {
if (!isset($elements[$v]) || empty($elements[$v])) {
continue;
}
$fieldDefinitions[$v] = $elements[$v]['#type'];
}
}
return $fieldDefinitions;
}