- // Trigger a standardized text editor configuration event to indicate
- // whether a feature was added or removed, so that filters can react.
- const configEvent = (action === 'added') ? 'addedFeature' : 'removedFeature';
- Drupal.editorConfiguration[configEvent](feature);
- })
- // Listen for CKEditor plugin settings changes. When a plugin setting is
- // changed, rebuild the CKEditor features metadata.
- .on('CKEditorPluginSettingsChanged.ckeditorAdmin', (event, settingsChanges) => {
- // Update hidden CKEditor configuration.
- Object.keys(settingsChanges || {}).forEach((key) => {
- hiddenEditorConfig[key] = settingsChanges[key];
- });
+ if (Drupal.editorConfiguration.featureIsAllowedByFilters(feature)) {
+ // Existing toolbar buttons are in fact "added features".
+ this.$el
+ .find('.ckeditor-toolbar-active')
+ .trigger('CKEditorToolbarChanged', ['added', existingButtons[n]]);
+ } else {
+ // Move the button element from the active the active toolbar to the
+ // list of available buttons.
+ $(
+ `.ckeditor-toolbar-active li[data-drupal-ckeditor-button-name="${button}"]`,
+ )
+ .detach()
+ .appendTo(
+ '.ckeditor-toolbar-disabled > .ckeditor-toolbar-available > ul',
+ );
+ // Update the toolbar value field.
+ this.model.set({ isDirty: true }, { broadcast: false });
+ }
+ }
+ },
+
+ /**
+ * Sets up broadcasting of CKEditor toolbar configuration changes.
+ *
+ * @param {jQuery} $ckeditorToolbar
+ * The active toolbar DOM element wrapped in jQuery.
+ */
+ broadcastConfigurationChanges($ckeditorToolbar) {
+ const view = this;
+ const hiddenEditorConfig = this.model.get('hiddenEditorConfig');
+ const getFeatureForButton = this.getFeatureForButton.bind(this);
+ const getCKEditorFeatures = this.getCKEditorFeatures.bind(this);
+ $ckeditorToolbar
+ .find('.ckeditor-toolbar-active')
+ // Listen for CKEditor toolbar configuration changes. When a button is
+ // added/removed, call an appropriate Drupal.editorConfiguration method.
+ .on(
+ 'CKEditorToolbarChanged.ckeditorAdmin',
+ (event, action, button) => {
+ const feature = getFeatureForButton(button);