Deprecated function: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Component\Utility\Unicode::validateUtf8()

Created on 9 March 2023, almost 2 years ago
Updated 9 July 2023, over 1 year ago

Problem/Motivation

Iยดm getting two errors if I use my own embedded content moduls when I am launching the embedded content form:

Deprecated function: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Component\Utility\Unicode::validateUtf8()

and

Deprecated function: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in Drupal\Component\Utility\Xss::filter()

This is because the $config variable is an empty array (array()) in the function "buildForm" within the "EmbeddedContentDialogForm.php" in line 69.

Steps to reproduce

  1. Install the module with the demo submodul
  2. Launch the embedded content icon in the ckeditor

Proposed resolution

Change line 70 from
if(!$config){
to
if(!isset($config)){

Remaining tasks

Create fix

User interface changes

none

API changes

none

Data model changes

none

๐Ÿ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

๐Ÿ‡ฉ๐Ÿ‡ชGermany dbielke1986

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @dbielke1986
  • Status changed to Needs review almost 2 years ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Adil_Siddiqui

    Patch created

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany dbielke1986

    Great!!!! It is working for me.

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany dbielke1986

    Unfortunately, this does not yet work as desired.
    If you double-click on an existing embedded content to customize the content, the current plugin and its config are not pre-populated, but an initial dialog is called.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany dbielke1986

    It seems to be a better approach to use:

    $plugin_config = !empty($plugin_config) ? Xss::filter($plugin_config) : '';

    instead of code line 72
    $plugin_config = Xss::filter($plugin_config);

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States cecrs

    Fwiw, I was getting these issues due to a malformed array in my custom template. (Specifically the default_value for a text_format field, which has to be $this->configuration['']['value'], not $this->configuration['']. No patches were necessary.

    Just as an fyi, to render a formatted field in the twig template, you will need to use this format:
    {% set descriptionFormatted = {
    '#type': 'processed_text',
    '#text': description.value,
    '#format': 'basic_html',
    }
    %}

    {{ descriptionFormatted }}

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany dbielke1986

    Hey @cecrs,

    thank you for your input and the great information!
    I already have the default value, as you described, but I still get an error if I do not change the code, or do you think this is because of the

    : NULL

    This is the code for my fields in the buildConfigurationForm

      public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
        // Create empty options array
        $options = array();
        
        $langcodes = \Drupal::languageManager()->getLanguages();
        
        // Inject into the options array
        foreach ($langcodes as $langcode => $key) {
          $options[$langcode] = $langcode;
        }
        
        $form['language'] = [
          '#type' => 'select',
          '#title' => $this->t('Language'),
          '#default_value' => $this->configuration['language'],
          '#required' => TRUE,
          '#options' => $options,
          '#ajax' => [
            'callback' => [$this, 'updateText'],
            'event' => 'change',
            'wrapper' => 'text-field-wrapper',
            'progress' => [
              'type' => 'throbber',
              'message' => $this->t('Verifying entry...'),
            ],        
          ],
        ];
        
        $form['text'] = [
          '#type' => 'text_format',
          '#format' => 'full_html',
          '#title' => $this->t('Text'),
          '#default_value' => (isset($this->configuration['text']['value']) ? $this->configuration['text']['value'] : NULL),
          '#prefix' => '<div id="text-field-wrapper">',
          '#suffix' => '</div>',
        ];
    
        return $form;
      }

    BR
    Daniel

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States cecrs

    @Daniel

    Possibly, I would suggest trying removing all except the minimal required config, clear cache see if it works. If it does, add things back one by one (clearing cache between each, natch) until it breaks. If not, the issue is somewhere else and my experience will be of no help... :P

    Working example:

        $form['text'] = array(
          '#type' => 'text_format',
          '#title' => $this->t('Text'),
          '#format' => 'basic_html',
          '#default_value' => $this->configuration['text']['value'],
        );
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany dbielke1986

    @cecrs:

    I have realized that this error occurs even without my custom module. So, just activate the CKEditor5 embedded content module and click the button to insert a template.

    Here comes then this message, but also the above PHP errors.

  • Anybody got this fixed? After applying the patch the deprecation error is fixed, but as mentioned in comment #5 now we are not able to edit the existing embed content. When we double click on the existing embedded content its opening a new dialog instead of opening the dialog with the existing values

  • Status changed to Fixed over 1 year ago
  • ๐Ÿ‡ช๐Ÿ‡ธSpain nuez Madrid, Spain

    Thank you, I've incorporated the suggestions in the latest dev release. Feel free to reopen if this is still is an issue

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

Production build 0.71.5 2024