Skip to content
Snippets Groups Projects
Verified Commit c1927736 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3479411 by phenaproxima, thejimbirch: The addItemToToolbar config...

Issue #3479411 by phenaproxima, thejimbirch: The addItemToToolbar config action should not, by default, add items that are already in the toolbar
parent 85dc67bf
No related branches found
No related tags found
13 merge requests!11197Issue #3506427 by eduardo morales alberti: Remove responsive_image.ajax from hook,!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!10786Issue #3490579 by shalini_jha, mstrelan: Add void return to all views...,!10210Issue #3487907: Drupal.displace() use getComputedStyle() for hidden chk.,!1010411.1.x,!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2062Issue #3246454: Add weekly granularity to views date sort,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation
Pipeline #328697 passed with warnings
Pipeline: drupal

#328708

    Pipeline: drupal

    #328700

      Pipeline: drupal

      #328699

        +1
        ...@@ -47,30 +47,40 @@ public function apply(string $configName, mixed $value): void { ...@@ -47,30 +47,40 @@ public function apply(string $configName, mixed $value): void {
        throw new ConfigActionException(sprintf('The %s config action only works with editors that use CKEditor 5.', $this->pluginId)); throw new ConfigActionException(sprintf('The %s config action only works with editors that use CKEditor 5.', $this->pluginId));
        } }
        $editor_settings = $editor->getSettings();
        if (is_string($value)) { if (is_string($value)) {
        $editor_settings['toolbar']['items'][] = $item_name = $value; $value = ['item_name' => $value];
        } }
        else { assert(is_array($value));
        assert(is_array($value));
        $item_name = $value['item_name']; $item_name = $value['item_name'];
        assert(is_string($item_name)); assert(is_string($item_name));
        $replace = $value['replace'] ?? FALSE; $replace = $value['replace'] ?? FALSE;
        assert(is_bool($replace)); assert(is_bool($replace));
        $position = $value['position'] ?? NULL; $position = $value['position'] ?? NULL;
        if (is_int($position)) {
        // If we want to replace the item at this position, then `replace` $allow_duplicate = $value['allow_duplicate'] ?? FALSE;
        // should be true. This would be useful if, for example, we wanted to assert(is_bool($allow_duplicate));
        // replace the Image button with the Media Library.
        array_splice($editor_settings['toolbar']['items'], $position, $replace ? 1 : 0, $item_name); $editor_settings = $editor->getSettings();
        }
        else { // If the item is already in the toolbar and we're not allowing duplicate
        $editor_settings['toolbar']['items'][] = $item_name; // items, we're done.
        } if (in_array($item_name, $editor_settings['toolbar']['items'], TRUE) && $allow_duplicate === FALSE && $item_name !== '|') {
        return;
        }
        if (is_int($position)) {
        // If we want to replace the item at this position, then `replace`
        // should be true. This would be useful if, for example, we wanted to
        // replace the Image button with the Media Library.
        array_splice($editor_settings['toolbar']['items'], $position, $replace ? 1 : 0, $item_name);
        } }
        else {
        $editor_settings['toolbar']['items'][] = $item_name;
        }
        // If we're just adding a vertical separator, there's nothing else we need // If we're just adding a vertical separator, there's nothing else we need
        // to do at this point. // to do at this point.
        if ($item_name === '|') { if ($item_name === '|') {
        ......
        ...@@ -69,6 +69,8 @@ protected function setUp(): void { ...@@ -69,6 +69,8 @@ protected function setUp(): void {
        * [{"item_name": "sourceEditing"}, ["heading", "bold", "italic", "sourceEditing"]] * [{"item_name": "sourceEditing"}, ["heading", "bold", "italic", "sourceEditing"]]
        * [{"item_name": "sourceEditing", "position": 1}, ["heading", "sourceEditing", "bold", "italic"]] * [{"item_name": "sourceEditing", "position": 1}, ["heading", "sourceEditing", "bold", "italic"]]
        * [{"item_name": "sourceEditing", "position": 1, "replace": true}, ["heading", "sourceEditing", "italic"]] * [{"item_name": "sourceEditing", "position": 1, "replace": true}, ["heading", "sourceEditing", "italic"]]
        * [{"item_name": "bold"}, ["heading", "bold", "italic"]]
        * [{"item_name": "bold", "allow_duplicate": true}, ["heading", "bold", "italic", "bold"]]
        */ */
        public function testAddItemToToolbar(string|array $action, array $expected_toolbar_items): void { public function testAddItemToToolbar(string|array $action, array $expected_toolbar_items): void {
        $recipe = $this->createRecipe([ $recipe = $this->createRecipe([
        ...@@ -86,8 +88,11 @@ public function testAddItemToToolbar(string|array $action, array $expected_toolb ...@@ -86,8 +88,11 @@ public function testAddItemToToolbar(string|array $action, array $expected_toolb
        /** @var array{toolbar: array{items: string[]}, plugins: array<string, array<mixed>>} $settings */ /** @var array{toolbar: array{items: string[]}, plugins: array<string, array<mixed>>} $settings */
        $settings = Editor::load('filter_test')?->getSettings(); $settings = Editor::load('filter_test')?->getSettings();
        $this->assertSame($expected_toolbar_items, $settings['toolbar']['items']); $this->assertSame($expected_toolbar_items, $settings['toolbar']['items']);
        // The plugin's default settings should have been added. // The plugin's default settings should have been added.
        $this->assertSame([], $settings['plugins']['ckeditor5_sourceEditing']['allowed_tags']); if (in_array('sourceEditing', $expected_toolbar_items, TRUE)) {
        $this->assertSame([], $settings['plugins']['ckeditor5_sourceEditing']['allowed_tags']);
        }
        } }
        public function testAddNonExistentItem(): void { public function testAddNonExistentItem(): void {
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Finish editing this message first!
        Please register or to comment