class TextFieldMapping in Webform Content Creator 3.x
Provides a text field mapping.
Plugin annotation
@WebformContentCreatorFieldMapping(
id = "text_mapping",
label = @Translation("Text"),
weight = 0,
field_types = {
"telephone",
"text",
"text_long",
"text_with_summary",
"string",
"string_long",
},
)
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\TextFieldMapping
- class \Drupal\webform_content_creator\Plugin\FieldMappingBase implements FieldMappingInterface
Expanded class hierarchy of TextFieldMapping
File
- src/
Plugin/ WebformContentCreator/ FieldMapping/ TextFieldMapping.php, line 29
Namespace
Drupal\webform_content_creator\Plugin\WebformContentCreator\FieldMappingView source
class TextFieldMapping extends FieldMappingBase {
public function getSupportedWebformFields($webform_id) {
$supported_types = array_merge([
"string",
"string_long",
"tel",
], FieldMappingInterface::WEBFORM_TEXT_ELEMENTS, FieldMappingInterface::WEBFORM_OPTIONS_ELEMENTS);
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];
$max_length = $this
->checkMaxFieldSizeExceeded($field_definition, $field_value);
if ($max_length === 0) {
$content
->set($field_id, $field_value);
}
else {
$content
->set($field_id, substr($field_value, 0, $max_length));
}
}
/**
* Check if field maximum size is exceeded.
*
* @param FieldDefinitionInterface $field_definition
* Field definition
* @param string $value
* Field value.
*
* @return int
* The max length or length of field, otherwise return 0.
*/
protected function checkMaxFieldSizeExceeded(FieldDefinitionInterface $field_definition, $value = "") {
$field_settings = $field_definition
->getSettings();
if (empty($field_settings) || !array_key_exists('max_length', $field_settings)) {
return 0;
}
$max_length = $field_settings['max_length'];
if (empty($max_length)) {
return 0;
}
if ($max_length < strlen($value)) {
\Drupal::logger(WebformContentCreatorInterface::WEBFORM_CONTENT_CREATOR)
->notice($this
->t('Problem: Field max length exceeded (truncated).'));
return $max_length;
}
return strlen($value);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
FieldMappingBase:: |
public | function |
Returns whether the mapper supports custom field text Overrides FieldMappingInterface:: |
2 |
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 |
TextFieldMapping:: |
protected | function | Check if field maximum size is exceeded. | |
TextFieldMapping:: |
public | function |
Overrides FieldMappingBase:: |
|
TextFieldMapping:: |
public | function |
Use a single mapping to set an entity field value. Overrides FieldMappingBase:: |