BooleanFieldMapping.php in Webform Content Creator 3.x
File
src/Plugin/WebformContentCreator/FieldMapping/BooleanFieldMapping.php
View source
<?php
namespace Drupal\webform_content_creator\Plugin\WebformContentCreator\FieldMapping;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\webform\WebformSubmissionInterface;
use Drupal\webform_content_creator\Plugin\FieldMappingBase;
class BooleanFieldMapping extends FieldMappingBase {
public function getSupportedWebformFields($webform_id) {
$supported_types = [
"boolean",
"checkbox",
];
return $this
->filterWebformFields($webform_id, $supported_types);
}
public function mapEntityField(ContentEntityInterface &$content, array $webform_element, array $data = [], FieldDefinitionInterface $field_definition) {
$field_id = $field_definition
->getName();
$field_value = $data[$field_id];
if (!is_bool($field_value)) {
$field_value = filter_var($field_value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
}
if (isset($field_value)) {
$content
->set($field_id, $field_value);
}
}
}