TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (line 141 of modules/contrib/ckeditor5_font/src/FontColorsManager.php).

CommentFileSizeAuthor
#6 interdiff.txt700 bytesrenatog
#6 3350333-5.patch511 bytesrenatog
array-filter-error.png509.24 KBsujan shrestha
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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sujan shrestha created an issue. See original summary.

renatog’s picture

Priority: Normal » Major
Status: Active » Reviewed & tested by the community
Related issues: +#3307786: Error after installing CKEditor 5 - Font Plugin

The solution proposed worked fine for me. Thanks for that - Marking as RTBC

This is the same fix of @maunm at #3307786-10: Error after installing CKEditor 5 - Font Plugin and as cited on this issue it's very importante so I'm updating the priority to "Major", ok?

renatog’s picture

My only suggestion in the code is to follow the S.O.L.I.D recommendation that says to avoid using the else clause

For example, instead of:

if(is_array($colors)) {
    return array_filter($colors, function ($clr) {
        return preg_match('/^#(?:[0-9a-f]{3}){1,2}$/i', $clr['color']);
    });
} else {
    return [];
}

We can verify first if we don't have $colors and return array [] as a default. If pass on this verification we return the "normal" value. Example:

if (empty($colors)) return [];

return array_filter($colors, function ($clr) {
    return preg_match('/^#(?:[0-9a-f]{3}){1,2}$/i', $clr['color']);
});
renatog’s picture

Version: 1.1.2-beta1 » 1.x-dev

'

renatog’s picture

FileSize
511 bytes
700 bytes

Updated the MR with this suggestion from #4, and I'm also uploading a patch for 1.1.2-beta1 so if someone needs as a workaround can apply that using composer

Piotr Pakulski’s picture

thank you @renatog patch 5 works great for me

chike’s picture

The patch at #6 (patch 5) is working.

brad.bulger’s picture

should that test on is_array() rather than empty()?

renatog credited devicious.

renatog’s picture

Status: Reviewed & tested by the community » Fixed

thanks everyone

Status: Fixed » Closed (fixed)

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

dbielke1986’s picture

Is there a chance to put this in a new release to get this module to a stable version?