class AddressFieldMapping in Webform Content Creator 3.x
Provides an address field mapping.
Plugin annotation
@WebformContentCreatorFieldMapping(
id = "address_mapping",
label = @Translation("Address"),
weight = 0,
field_types = {
"address",
},
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\webform_content_creator\Plugin\FieldMappingBase implements FieldMappingInterface
- class \Drupal\webform_content_creator\Plugin\WebformContentCreator\FieldMapping\AddressFieldMapping
- class \Drupal\webform_content_creator\Plugin\FieldMappingBase implements FieldMappingInterface
Expanded class hierarchy of AddressFieldMapping
File
- src/
Plugin/ WebformContentCreator/ FieldMapping/ AddressFieldMapping.php, line 21
Namespace
Drupal\webform_content_creator\Plugin\WebformContentCreator\FieldMappingView source
class AddressFieldMapping extends FieldMappingBase {
public function supportsCustomFields() {
return FALSE;
}
public function getSupportedWebformFields($webform_id) {
$supported_types = [
"address",
"webform_address",
];
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 = $field_definition
->getDefaultValue($content)[0];
if ($webform_element[$field_id]['#type'] == "webform_address") {
if (!empty($data[$field_id]['address'])) {
$field_value['address_line1'] = $data[$field_id]['address'];
}
if (!empty($data[$field_id]['address_2'])) {
$field_value['address_line2'] = $data[$field_id]['address_2'];
}
if (!empty($data[$field_id]['city'])) {
$field_value['locality'] = $data[$field_id]['city'];
}
if (!empty($data[$field_id]['state_province'])) {
$field_value['administrative_area'] = $data[$field_id]['state_province'];
}
if (!empty($data[$field_id]['postal_code'])) {
$field_value['postal_code'] = $data[$field_id]['postal_code'];
}
if (!empty($data[$field_id]['country'])) {
$field_value['country_code'] = $data[$field_id]['country'];
}
}
else {
$field_value = array_merge($field_value, $data[$field_id]);
}
$content
->set($field_id, $field_value);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AddressFieldMapping:: |
public | function |
Overrides FieldMappingBase:: |
|
AddressFieldMapping:: |
public | function |
Use a single mapping to set an entity field value. Overrides FieldMappingBase:: |
|
AddressFieldMapping:: |
public | function |
Returns whether the mapper supports custom field text Overrides FieldMappingBase:: |
|
FieldMappingBase:: |
protected | function | ||
FieldMappingBase:: |
public | function |
Returns the entity component fields. Overrides FieldMappingInterface:: |
1 |
FieldMappingBase:: |
public | function | Get the field types this plugin is available for. | |
FieldMappingBase:: |
public | function | Get the plugin ID. | |
FieldMappingBase:: |
public | function | Get the plugin label. | |
FieldMappingBase:: |
public | function | Return the plugin. | |
FieldMappingBase:: |
public | function | Get the plugin weight. | |
FieldMappingBase:: |
public | function | Is this a generic (non-element specific) plugin. | |
FieldMappingInterface:: |
constant | |||
FieldMappingInterface:: |
constant | |||
FieldMappingInterface:: |
constant | |||
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 98 |