public function CKEditor::buildConfigurationForm in Drupal 10
Same name and namespace in other branches
- 8 core/modules/ckeditor/src/Plugin/Editor/CKEditor.php \Drupal\ckeditor\Plugin\Editor\CKEditor::buildConfigurationForm()
- 9 core/modules/ckeditor/src/Plugin/Editor/CKEditor.php \Drupal\ckeditor\Plugin\Editor\CKEditor::buildConfigurationForm()
File
- core/modules/ckeditor/src/Plugin/Editor/CKEditor.php, line 176
Class
- CKEditor
- Defines a CKEditor-based text editor for Drupal.
Namespace
Drupal\ckeditor\Plugin\Editor
Code
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$editor = $form_state
->get('editor');
$settings = $editor
->getSettings();
$ckeditor_settings_toolbar = [
'#theme' => 'ckeditor_settings_toolbar',
'#editor' => $editor,
'#plugins' => $this->ckeditorPluginManager
->getButtons(),
];
$form['toolbar'] = [
'#type' => 'container',
'#attached' => [
'library' => [
'ckeditor/drupal.ckeditor.admin',
],
'drupalSettings' => [
'ckeditor' => [
'toolbarAdmin' => (string) $this->renderer
->renderPlain($ckeditor_settings_toolbar),
],
],
],
'#attributes' => [
'class' => [
'ckeditor-toolbar-configuration',
],
],
];
$form['toolbar']['button_groups'] = [
'#type' => 'textarea',
'#title' => $this
->t('Toolbar buttons'),
'#default_value' => json_encode($settings['toolbar']['rows']),
'#attributes' => [
'class' => [
'ckeditor-toolbar-textarea',
],
],
];
$form['plugin_settings'] = [
'#type' => 'vertical_tabs',
'#title' => $this
->t('CKEditor plugin settings'),
'#attributes' => [
'id' => 'ckeditor-plugin-settings',
],
];
$this->ckeditorPluginManager
->injectPluginSettingsForm($form, $form_state, $editor);
if (count(Element::children($form['plugins'])) === 0) {
unset($form['plugins']);
unset($form['plugin_settings']);
}
$plugins = array_keys($this->ckeditorPluginManager
->getDefinitions());
$all_external_plugins = [];
foreach ($plugins as $plugin_id) {
$plugin = $this->ckeditorPluginManager
->createInstance($plugin_id);
if (!$plugin
->isInternal()) {
$all_external_plugins[$plugin_id] = $plugin
->getFile();
}
}
$all_buttons = array_reduce($this->ckeditorPluginManager
->getButtons(), function ($result, $item) {
return array_merge($result, array_keys($item));
}, []);
$fake_editor = Editor::create([
'format' => $editor
->id(),
'editor' => 'ckeditor',
'settings' => [
'toolbar' => [
'rows' => [
0 => [
0 => [
'name' => 'All existing buttons',
'items' => $all_buttons,
],
],
],
],
'plugins' => $settings['plugins'],
],
]);
$config = $this
->getJSSettings($fake_editor);
unset($config['allowedContent']);
$form['hidden_ckeditor'] = [
'#markup' => '<div id="ckeditor-hidden" class="hidden"></div>',
'#attached' => [
'drupalSettings' => [
'ckeditor' => [
'hiddenCKEditorConfig' => $config,
],
],
],
];
return $form;
}