protected static function TextFieldCounterWidgetTrait::getLengthOfSubmittedValue in Textfield Counter 8
Get the length of the submitted text value.
Parameters
array $element: The form element.
string $value: The value whose length is to be calcluated.
Return value
int The length of the value.
1 call to TextFieldCounterWidgetTrait::getLengthOfSubmittedValue()
- TextFieldCounterWidgetTrait::validateFieldFormElement in src/
Plugin/ Field/ FieldWidget/ TextFieldCounterWidgetTrait.php - Validates the field for the maximum number of characters.
File
- src/
Plugin/ Field/ FieldWidget/ TextFieldCounterWidgetTrait.php, line 376
Class
- TextFieldCounterWidgetTrait
- Textfield counter trait. Adds textfield counting functionality.
Namespace
Drupal\textfield_counter\Plugin\Field\FieldWidgetCode
protected static function getLengthOfSubmittedValue(array $element, string $value) : int {
$parts = explode(PHP_EOL, $value);
$newline_count = count($parts) - 1;
$count_html_characters = $element['#textfield-count-html'];
if ($count_html_characters) {
$value_length = mb_strlen($value) - $newline_count;
}
else {
$value_length = str_replace(' ', ' ', $value);
$value_length = trim($value_length);
$value_length = preg_replace("/(\r?\n|\r)+/", "\n", $value_length);
$value_length = mb_strlen(strip_tags($value_length));
}
return $value_length;
}