How to add options from PHP to select list in CKeditor dialog

I am building a CKEditor plugin for Drupal 8. Currently it adds a toolbar button which triggers a modal dialog containing a select list with a few options. I've hardcoded the options in the plugin.js file and everything works as expected.

But IRL, those options should be dynamically added from php. I've been reviewing the classes and interfaces under /core/modules/ckeditor/src without finding clues on how to achieve this.

This is my plugin dialog definition, as per!/api/ with hardcoded options. This goes in the plugin.js file loaded via CKEditorPluginInterface::getFile() in my plugin class:

CKEDITOR.dialog.add('pluginDialog', function(editor) {   return {     title: 'Available options',     minWidth: 300,     minHeight: 200,     resizable: CKEDITOR.DIALOG_RESIZE_BOTH,     setup: function(e) {},     commit: function(e) {},      contents: [{       id: 'tab-options',       elements: [{         type: 'select',         id: 'select-options',         label: 'Select an option:',         items: [           ['Option 1', '<span>Option 1</span>'],           ['Option 2', '<span>Option 2</span>'],           ['Option 3', '<span>Option 3</span>'],           ['Option 4', '<span>Option 4</span>']         ]       }]     }]   }; }); 

CKEDITOR.dialog.definition.contents.elements.items[] have to be built from PHP. Any help is appreciated.


Category: 8 Time: 2016-07-28 Views: 0
Tags: ckeditor

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.288 (s). 12 q(s)