FriendsOfSymfony / FOSCKEditorBundle

Provides a CKEditor integration for your Symfony project.
Other
518 stars 83 forks source link

Swap array_merge options for resolving custom/default config #173

Closed x1oJ0 closed 5 years ago

x1oJ0 commented 5 years ago
Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Fixed tickets #172
License MIT

Swap config merge to allow users use custom settings for editor.

kunicmarko20 commented 5 years ago

Can you please add a test case that covers this change?

x1oJ0 commented 5 years ago

Can you please add a test case that covers this change?

Hey @kunicmarko20, sure.

In this example, we setup custom toolbar in config:

fos_ck_editor:
    default_config: simple_toolbar
    configs:
        forcePasteAsPlainText: true
        simple_toolbar:
            toolbar:
                - ['Undo', 'Redo']
                - ['Format']
                - ['Bold', 'Italic', 'Strike', 'Subscript', 'Superscript' ]
                - ['Link', 'Unlink']
                - ['RemoveFormat']
                - ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock']
                - ['BulletedList', 'NumberedList', '-', 'Outdent', 'Indent']
                - ['Image', 'Table', 'CodeSnippet']
                - ['Copy']
                - ['Source']
            filebrowserBrowseRoute: elfinder
            filebrowserBrowseRouteParameters: []
            htmlEncodeOutput: false

But this change does not take any effect, because settings in src/Form/Type/CKEditorType.php on line 72 takes precedence for default config and rewrite ours. If we swap the values in array_merge, our config just works fine.

kunicmarko20 commented 5 years ago

So this is just an example, not a test case. I wrote a test case and I don't get your point with this PR.

If I have this default config:

fos_ck_editor:
    default_config: simple_toolbar
    configs:
        simple_toolbar:
            toolbar:
                - ['Undo', 'Redo']

and I call:

$this->createForm(CKEditorType::class);

The output is:

array(1) {
  ["toolbar"]=>
  array(1) {
    [0]=>
    array(2) {
      [0]=>
      string(4) "Undo"
      [1]=>
      string(4) "Redo"
    }
  }
}

when I call with custom config:

$this->createForm(CKEditorType::class, null, ['config' => ['toolbar' => [['Format']]]]);

the output is:

array(1) {
  ["toolbar"]=>
  array(1) {
    [0]=>
    array(1) {
      [0]=>
      string(6) "Format"
    }
  }
}

If I apply this PR change and call:

$this->createForm(CKEditorType::class, null, ['config' => ['toolbar' => [['Format']]]]);

the output is:

array(1) {
  ["toolbar"]=>
  array(1) {
    [0]=>
    array(2) {
      [0]=>
      string(4) "Undo"
      [1]=>
      string(4) "Redo"
    }
  }
}

And this is wrong, the toolbar should be only Format since the custom config is passed. Am I misunderstanding something here?

kunicmarko20 commented 5 years ago

@hasakm @ondrajonas am I missing something in my last comment?

kunicmarko20 commented 5 years ago

Closing as no response.