Passing NULL to mb_strlen() with PHP 8.1 in Views UI module

Created on 4 July 2023, 12 months ago

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

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
Views UIΒ  β†’

Last updated 2 days ago

Created by

πŸ‡©πŸ‡ͺGermany zcht

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Comments & Activities

  • Issue created by @zcht
  • Status changed to Needs review 12 months ago
  • last update 12 months ago
    Custom Commands Failed
  • πŸ‡©πŸ‡ͺGermany zcht

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

  • Status changed to Needs work 12 months ago
  • πŸ‡ΊπŸ‡ΈUnited States cilefen

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

  • πŸ‡©πŸ‡ͺGermany zcht

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

  • πŸ‡ΊπŸ‡ΈUnited States cilefen

    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.

  • Status changed to Needs review 12 months ago
  • last update 12 months ago
    Custom Commands Failed
  • πŸ‡©πŸ‡ͺGermany zcht

    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.
  • Status changed to Needs work 12 months ago
  • πŸ‡ΊπŸ‡ΈUnited States cilefen
Production build 0.69.0 2024