In many languages, counting letters does not work correctly.
In the previous Drupal 7 version we used drupal_strlen() function.
if (drupal_strlen($node->title) > $type_max_chars) {
form_set_error('title', t("Title should not exceed @num characters", array('@num' => $type_max_chars)));
}
Now we need use Drupal\Component\Utility\Unicode::strlen(). It counts the number of characters in a UTF-8 string.
if (Unicode::strlen($value_title) > $config_value) {
$this->context->addViolation("Title should not exceed $config_value character(s)");
}
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | node_title_validation-unicode-3000029-7.patch | 1.86 KB | renrhaf |
| #2 | validation_node_title_unicode.PNG | 7.08 KB | krzysztof domański |
Comments
Comment #2
krzysztof domańskiComment #3
krzysztof domańskiComment #5
krzysztof domańskiNo tests foundThis module does not contain any tests, so I change the status again to Needs review.
Comment #6
krzysztof domańskiComment #7
renrhafThe class Drupal\Component\Utility\Unicode has a deprecation notice for this method, see https://www.drupal.org/node/2850048.
Using "mb_strlen" instead of regular "strlen" for UTF8 special chars support.
Comment #9
cgomezgComment #11
cgomezgMerged in 8.x-1.x-dev