protected function TextFieldMapping::checkMaxFieldSizeExceeded in Webform Content Creator 3.x
Check if field maximum size is exceeded.
Parameters
FieldDefinitionInterface $field_definition: Field definition
string $value: Field value.
Return value
int The max length or length of field, otherwise return 0.
1 call to TextFieldMapping::checkMaxFieldSizeExceeded()
- TextFieldMapping::mapEntityField in src/
Plugin/ WebformContentCreator/ FieldMapping/ TextFieldMapping.php - Use a single mapping to set an entity field value.
File
- src/
Plugin/ WebformContentCreator/ FieldMapping/ TextFieldMapping.php, line 65
Class
- TextFieldMapping
- Provides a text field mapping.
Namespace
Drupal\webform_content_creator\Plugin\WebformContentCreator\FieldMappingCode
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);
}