Skip to content

Commit

Permalink
Issue #113: Rename config key to toolbar.
Browse files Browse the repository at this point in the history
  • Loading branch information
quicksketch committed Dec 11, 2023
1 parent 4bc317e commit aeb23bf
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 14 deletions.
10 changes: 5 additions & 5 deletions ckeditor5.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ function ckeditor5_settings_form(&$form, $form_state, $format) {
),
'#attributes' => array('class' => array('ckeditor5-toolbar-configuration')),
);
$elements['cketoolbar'] = array(
$elements['toolbar'] = array(
'#type' => 'textarea',
'#title' => t('Toolbar configuration'),
'#default_value' => json_encode($format->editor_settings['cketoolbar']),
'#default_value' => json_encode($format->editor_settings['toolbar']),
'#attributes' => array('class' => array('ckeditor5-toolbar-textarea')),
);

Expand Down Expand Up @@ -122,10 +122,10 @@ function ckeditor5_settings_form_validate($form, &$form_state) {
// Get rid of submission values caused by vertical tabs.
unset($form_state['values']['editor_settings']['plugins']);
$settings = $form_state['values']['editor_settings'];
$toolbar_string = $settings['cketoolbar'];
$toolbar_string = $settings['toolbar'];
$result = json_decode($toolbar_string, TRUE);
if (empty($result)) {
form_error($form['editor_settings']['cketoolbar'], t('The CKEditor toolbar configuration could not be saved.'));
form_error($form['editor_settings']['toolbar'], t('The CKEditor toolbar configuration could not be saved.'));
}

$styles = _ckeditor5_settings_parse_style_list($settings['style_list']);
Expand All @@ -143,7 +143,7 @@ function ckeditor5_settings_form_submit($form, &$form_state) {
$settings = $form_state['values']['editor_settings'];

// Convert JSON toolbar settings to an array.
form_set_value($form['editor_settings']['cketoolbar'], json_decode($settings['cketoolbar'], TRUE), $form_state);
form_set_value($form['editor_settings']['toolbar'], json_decode($settings['toolbar'], TRUE), $form_state);

// Convert string style list into an array.
$styles = _ckeditor5_settings_parse_style_list($settings['style_list']);
Expand Down
2 changes: 1 addition & 1 deletion ckeditor5.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function hook_ckeditor5_settings_alter(array &$settings, $format) {
*/
function hook_ckeditor5_PLUGIN_plugin_check($format, $plugin_name) {
// Automatically enable this plugin if the Underline button is enabled.
foreach ($format->editor_settings['cketoolbar']['buttons'] as $row) {
foreach ($format->editor_settings['toolbar']['buttons'] as $row) {
if (in_array('Underline', $row)) {
return TRUE;
}
Expand Down
18 changes: 18 additions & 0 deletions ckeditor5.install
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,21 @@ function ckeditor5_requirements($phase) {

return $requirements;
}

/**
* Updates the editor settings key from "cketoolbar" to just "toolbar".
*/
function ckeditor5_update_1000() {
$config_names = config_get_names_with_prefix('filter.format');
foreach ($config_names as $config_name) {
$config = config($config_name);
if ($config['editor'] === 'ckeditor5' && isset($config['editor_settings']['cketoolbar'])) {
$editor_settings = $config['editor_settings'];
$toolbar = $editor_settings['cketoolbar'];
unset($editor_settings['cketoolbar']);
$config['editor_settings'] = array_merge(array(
'toolbar' => $toolbar,
), $editor_settings);
}
}
}
8 changes: 4 additions & 4 deletions ckeditor5.module
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function ckeditor5_editor_info() {
'label' => t('CKEditor 5'),
'library' => array('ckeditor5', 'backdrop.ckeditor5'),
'default settings' => array(
'cketoolbar' => array(
'toolbar' => array(
'bold', 'italic', 'blockQuote', 'heading', '|',
'bulletedList', 'numberedList', '|',
'alignment:left', 'alignment:center', 'alignment:right', '|',
Expand Down Expand Up @@ -837,8 +837,8 @@ function _ckeditor5_image_alignment_plugin_check($format, $plugin_name) {
* TRUE if the image plugin is enabled, FALSE otherwise.
*/
function _ckeditor5_link_image_plugin_check($format, $plugin_name) {
$link_enabled = in_array('backdropLink', $format->editor_settings['cketoolbar']);
$image_enabled = in_array('backdropImage', $format->editor_settings['cketoolbar']);
$link_enabled = in_array('backdropLink', $format->editor_settings['toolbar']);
$image_enabled = in_array('backdropImage', $format->editor_settings['toolbar']);
return $link_enabled && $image_enabled;
}

Expand Down Expand Up @@ -901,7 +901,7 @@ function ckeditor5_get_config($format) {

// Record needed plugins based on use in the toolbar.
$toolbar = array();
foreach ($format->editor_settings['cketoolbar'] as $button_name) {
foreach ($format->editor_settings['toolbar'] as $button_name) {
// Sanity check that the button exists in our installation.
if (isset($all_buttons[$button_name])) {
// Add in the button parent's overall plugin and its dependencies.
Expand Down
2 changes: 1 addition & 1 deletion ckeditor5.theme.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function template_preprocess_ckeditor5_settings_toolbar(&$variables) {

$active_buttons = array();
$settings = $format->editor_settings;
foreach ($settings['cketoolbar'] as $button_name) {
foreach ($settings['toolbar'] as $button_name) {
if (isset($buttons[$button_name])) {
$active_buttons[] = $buttons[$button_name];
if (empty($buttons[$button_name]['multiple'])) {
Expand Down
2 changes: 1 addition & 1 deletion js/ckeditor5.admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Backdrop.behaviors.ckeditor5Admin = {
// Set up toolbar drag-and-drop interface and add/remove allowed HTML tags.
$context.find('.ckeditor5-toolbar-configuration').once('ckeditor5-toolbar', function() {
const $wrapper = $(this);
const $textareaWrapper = $wrapper.find('.form-item-editor-settings-cketoolbar').hide();
const $textareaWrapper = $wrapper.find('.form-item-editor-settings-toolbar').hide();
const $textarea = $textareaWrapper.find('textarea');
const $toolbarAdmin = $(settings.ckeditor5.toolbarAdmin);
const sortableSettings = {
Expand Down
4 changes: 2 additions & 2 deletions tests/ckeditor5.test
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CKEditor5TestCase extends BackdropWebTestCase {
);

$this->backdropPost(NULL, array(
'editor_settings[cketoolbar]' => json_encode($toolbar),
'editor_settings[toolbar]' => json_encode($toolbar),
'filters[filter_autop][status]' => TRUE,
'filters[filter_image_align][status]' => TRUE,
'filters[filter_image_caption][status]' => TRUE,
Expand Down Expand Up @@ -108,7 +108,7 @@ class CKEditor5TestCase extends BackdropWebTestCase {
// Turn on the table plugin and check that the JavaScript is adjusted.
$toolbar = array('insertTable');
$this->backdropPost('admin/config/content/formats/ckeditor5', array(
'editor_settings[cketoolbar]' => json_encode($toolbar),
'editor_settings[toolbar]' => json_encode($toolbar),
'allowed_html' => '<a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <h3> <h4> <h5> <p> <img> <figure> <figcaption> <table> <thead> <tbody> <tr> <td> <th>',
), t('Save configuration'));
$this->backdropGet('node/add/article');
Expand Down

0 comments on commit aeb23bf

Please sign in to comment.