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)");
}

Comments

Krzysztof Domański created an issue. See original summary.

krzysztof domański’s picture

krzysztof domański’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: node_title_validation-unicode-3000029-2.patch, failed testing. View results

krzysztof domański’s picture

Status: Needs work » Needs review

No tests found

This module does not contain any tests, so I change the status again to Needs review.

krzysztof domański’s picture

Assigned: krzysztof domański » Unassigned
Issue tags: +Quick fix
renrhaf’s picture

StatusFileSize
new1.86 KB

The 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.

Status: Needs review » Needs work

The last submitted patch, 7: node_title_validation-unicode-3000029-7.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

cgomezg’s picture

Status: Needs work » Reviewed & tested by the community

  • cgomezg committed b278b56 on 8.x-1.x authored by Renrhaf
    Issue #3000029 by Krzysztof Domański, Renrhaf: Adding Unicode support...
cgomezg’s picture

Status: Reviewed & tested by the community » Fixed

Merged in 8.x-1.x-dev

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.