Problem/Motivation
In a contrib module issue with Drupal 10.1 and PHP 8.1, I found that the views_ui_truncate() function in views_ui.module file mb_strlen() function is used.
The mb_strlen() function can only handle strings in PHP 8.1 version. Thus, sometimes, or often, the following is output in conjunction with contrib modules:
Deprecated function: mb_strlen(): Passing null to parameter #1 ($string) of type string is deprecated in my_fancy_function() (line 123 of /modules/my_contrib/my_contrib.module).
In addition, the views_ui_truncate() function does not check whether the variable $string really has a value. The problem is indirectly related to the function, but the function needs to be made compatible with > PHP 8.1.
In a further step, the function could also be modernized and made more elegant.
- No words should be cut off in the middle.
- Unicode should be used for the placeholder instead of ASCII to save space. (three ordinary ASCII characters vs. one Unicode character)
- It should be possible to set your own placeholder.
- It should be processed as fast as possible and use PHP functions that are much faster than the ones used so far.
Steps to reproduce
Proposed resolution
- Provide a patch
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3372317--002-compatibility-modernization-views_ui_truncate.patch | 1.16 KB | zcht |
Issue fork drupal-3372317
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
zcht commentedHere would be my suggestion as a patch, recommendations and further evaluations are welcome.
Comment #3
cilefen commentedFor a bug report we need steps to reproduce the bug.
Comment #4
zcht commentedreroll patch, small error with the separator and thus duplicated string.
Comment #5
cilefen commentedThis should probably only fix the bug. Refactoring should be a separate issue. The more this is doing the more difficult it will be to have it committed.
Comment #6
zcht commentedThe problem arose with the 'Agreement' module in version 3.0.0-alpha2 (an issue will follow in the project), the error message was the following:
So I started to look in detail what the problem is, just discovered that the function
views_ui_truncate()as described by me is not error free under PHP 8.1.The problem with the contrib module Agreement has indirectly to do with the function I mentioned. However, I find that
views_ui_truncate()should be made more error-tolerant, although most of the problems will probably have to do with contrib.Comment #7
cilefen commentedComment #10
rafuel92 commentedi think that the views_ui_truncate does not exists anymore in the module.