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

Issue fork drupal-3372317

Command icon 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

zcht created an issue. See original summary.

zcht’s picture

Status: Active » Needs review
StatusFileSize
new1.17 KB

Here would be my suggestion as a patch, recommendations and further evaluations are welcome.

cilefen’s picture

Status: Needs review » Needs work
Issue tags: +Needs steps to reproduce

For a bug report we need steps to reproduce the bug.

zcht’s picture

StatusFileSize
new1.16 KB

reroll patch, small error with the separator and thus duplicated string.

cilefen’s picture

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

zcht’s picture

Status: Needs work » Needs review

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

Warning: Undefined array key "" in /var/www/html/docroot/core/modules/views_ui/src/ViewFormBase.php on line 162

Warning: Trying to access array offset on value of type null in /var/www/html/docroot/core/modules/views_ui/src/ViewFormBase.php on line 162

Deprecated: mb_strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/docroot/core/modules/views_ui/views_ui.module on line 347
The website encountered an unexpected error. Please try again later.

Error: Call to a member function isEnabled() on null in Drupal\views_ui\ViewEditForm->getDisplayDetails() (line 421 of core/modules/views_ui/src/ViewEditForm.php).
Drupal\views_ui\ViewEditForm->getDisplayTab(Object) (Line: 212)
Drupal\views_ui\ViewEditForm->form(Array, Object) (Line: 107)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object) (Line: 41)
Drupal\views_ui\ViewFormBase->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 536)
Drupal\Core\Form\FormBuilder->retrieveForm('view_edit_form', Object) (Line: 283)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 48)
Drupal\Core\Entity\EntityFormBuilder->getForm(Object, 'edit', Array) (Line: 230)
Drupal\views_ui\Controller\ViewsUIController->edit(Object, NULL)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 583)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 166)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 74)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

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

  • a) the function views_ui_truncate() should be made more error-tolerant, although most of the problems will probably have to do with contrib.
  • b) Compatibility for PHP 8.1 must be made anyway.
cilefen’s picture

Status: Needs review » Needs work

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

rafuel92 made their first commit to this issue’s fork.

rafuel92’s picture

i think that the views_ui_truncate does not exists anymore in the module.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.