Ckeditor5: How to pass data to a plugin?

Created on 17 Oct 2019  路  1Comment  路  Source: ckeditor/ckeditor5

I am implementing a dropdown which will display a list of items based on the array that I provide.

const DROPDOWN_ITEMS = [
  { value: "1", label: "First Name" },
  { value: "2", label: "Last Name" }
];

...

DROPDOWN_ITEMS.forEach(item => {
  return DropdownCollection.add({
    type: "button",
    model: new Model({
      withText: true,
      label: item.label,
      value: item.value
    })
  });
});

Now what if I wanted to pass the DROPDOWN_ITEMS array from outside the editor.

So probably <ReactCKEditor customData={ [...MYARRAY] } /> and then CKEditor passes the data to the other plugins and I can use it like DROPDOWN_ITEMS = editor.additionalData.MYARRAY or something like that.

Can this be done as of now? Using CKEditor 5 with a custom implemented plugin

question

Most helpful comment

You should be able to use editor.config object, like:

const editorConfiguration = {
    // other CKEditor5 configuration options,
    myDropdown: {
        items: [
            { value: "1", label: "First Name" },
            { value: "2", label: "Last Name" }
        ];
    }
}

<CKEditor
    editor={ ClassicEditor }
    data="<p>Hello from CKEditor 5!</p>"
    config={ editorConfiguration }
/>

then in your plugin just access it:

const items = editor.config.get( 'myDropdown.items' );

items.forEach( ... );

>All comments

You should be able to use editor.config object, like:

const editorConfiguration = {
    // other CKEditor5 configuration options,
    myDropdown: {
        items: [
            { value: "1", label: "First Name" },
            { value: "2", label: "Last Name" }
        ];
    }
}

<CKEditor
    editor={ ClassicEditor }
    data="<p>Hello from CKEditor 5!</p>"
    config={ editorConfiguration }
/>

then in your plugin just access it:

const items = editor.config.get( 'myDropdown.items' );

items.forEach( ... );
Was this page helpful?
0 / 5 - 0 ratings

Related issues

oleq picture oleq  路  3Comments

PaulParker picture PaulParker  路  3Comments

MansoorJafari picture MansoorJafari  路  3Comments

msamsel picture msamsel  路  3Comments

devaptas picture devaptas  路  3Comments