You are here

public function EntityReferenceFieldMapping::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/EntityReferenceFieldMapping.php, line 45

Class

EntityReferenceFieldMapping
Provides an entity reference field mapping.

Namespace

Drupal\webform_content_creator\Plugin\WebformContentCreator\FieldMapping

Code

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_array($field_value) && intval($field_value) === 0) {
    $content
      ->set($field_id, []);
  }
  else {
    $content
      ->set($field_id, $field_value);
  }
}