You are here

protected function FieldMappingBase::filterWebformFields in Webform Content Creator 3.x

9 calls to FieldMappingBase::filterWebformFields()
AddressFieldMapping::getSupportedWebformFields in src/Plugin/WebformContentCreator/FieldMapping/AddressFieldMapping.php
BooleanFieldMapping::getSupportedWebformFields in src/Plugin/WebformContentCreator/FieldMapping/BooleanFieldMapping.php
DateTimeFieldMapping::getSupportedWebformFields in src/Plugin/WebformContentCreator/FieldMapping/DateTimeFieldMapping.php
EmailFieldMapping::getSupportedWebformFields in src/Plugin/WebformContentCreator/FieldMapping/EmailFieldMapping.php
EntityReferenceFieldMapping::getSupportedWebformFields in src/Plugin/WebformContentCreator/FieldMapping/EntityReferenceFieldMapping.php

... See full list

File

src/Plugin/FieldMappingBase.php, line 78

Class

FieldMappingBase
Base for a field mapping plugin.

Namespace

Drupal\webform_content_creator\Plugin

Code

protected function filterWebformFields($webform_id, array $supported_types, array $available_fields = NULL) {
  if (!isset($available_fields)) {
    $available_fields = WebformContentCreatorUtilities::getWebformElements($webform_id);
  }
  $webform_field_types = WebformContentCreatorUtilities::getWebformElementsTypes($webform_id);
  $allowed_fields = [];
  foreach ($available_fields as $key => $available_field) {
    $key_parts = explode(',', $key);
    if (sizeOf($key_parts) > 1) {
      $element_type = $webform_field_types[$key_parts[1]];

      //Webform field vs user added fields
      if ($key_parts[0] == "1") {
        $element_type = $element_type['type'];
      }
      if (in_array($element_type, $supported_types)) {
        $allowed_fields[$key] = $available_field;
      }
    }
    else {

      //We're dealing with an option group, so recursive call to process the sub fields
      $retval = $this
        ->filterWebformFields($webform_id, $supported_types, $available_field);
      if (!empty($retval)) {
        $allowed_fields[$key] = $retval;
      }
    }
  }
  return $allowed_fields;
}