public function BooleanFieldMapping::mapEntityField in Webform Content Creator 3.x
Use a single mapping to set an entity field value.
Overrides FieldMappingBase::mapEntityField
File
- src/
Plugin/ WebformContentCreator/ FieldMapping/ BooleanFieldMapping.php, line 32
Class
- BooleanFieldMapping
- Provides a boolean field mapping.
Namespace
Drupal\webform_content_creator\Plugin\WebformContentCreator\FieldMappingCode
public function mapEntityField(ContentEntityInterface &$content, array $webform_element, array $data = [], FieldDefinitionInterface $field_definition) {
$field_id = $field_definition
->getName();
$field_value = $data[$field_id];
//Convert various strings (true, yes, on) to boolean
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);
}
}