Problem/Motivation

If a user with a role that does not have the use ck5 block embed button permission creates or edits a node, the following error is printed to the browser console:

ckeditor5.js:467 TypeError: e.filter is not a function
    at ho._cleanItemsConfiguration (ckeditor5-dll.js?v=44.0.0:5:607749)
    at ho._buildItemsFromConfig (ckeditor5-dll.js?v=44.0.0:5:607548)
    at ho.fillFromConfig (ckeditor5-dll.js?v=44.0.0:5:607444)
    at r._initToolbar (editor-classic.js?v=44.0.0:4:6873)
    at r.init (editor-classic.js?v=44.0.0:4:6304)
    at editor-classic.js?v=44.0.0:4:11594

This error occurs because of the CKeditor toolbar item array manipulation in the ck5_block_embed_editor_js_settings_alterfunction.

If the user does not have the use ck5 block embed button permission, the alter function tries to unset the CKeditor button from the array of the toolbar items. Unsetting the array elements in PHP causes Javascript to treat the toolbar item variable as an object and not as an array, which is the expected type.

Example:

// Array in PHP:
$array = [0 => 'zero', 1=> 'one', 2 => 'two'];
// The array translated into Javascript.
const arr = ['zero', 'one', 'two'];

// Array in PHP (with 'one' removed):
$array = [0 => 'zero', 2 => 'two'];
// Not an array anymore in Javascript:
const arr = {0: 'zero', 2: 'two'}

Steps to reproduce

  1. Log is as a user without the "use ck5 block embed button" permission.
  2. Go to the node creation page, where the CKeditor is displayed on the body or other field.
  3. See that the error is displayed in the browser console.

Proposed resolution

After unsetting an element from the CKeditor toolbar item array, re-index the array so that there are no skipped keys
in the PHP array. In Javascript this will nicely translate to an array.

CommentFileSizeAuthor
#2 e-not-function-3538578-2.diff595 bytesmaijs

Comments

maijs created an issue. See original summary.

maijs’s picture

Status: Active » Needs review
StatusFileSize
new595 bytes

Attaching a patch that fixes the issue by re-indexing the array after unsetting an element.