Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Config] Default configuration overriding #209

Open
fsoedjede opened this issue Jan 10, 2020 · 1 comment
Open

[Config] Default configuration overriding #209

fsoedjede opened this issue Jan 10, 2020 · 1 comment

Comments

@fsoedjede
Copy link

Environment

Symfony 4.4.2
PHP 7.3

Subject

I think there is an issue with configuration overriding.
When I set a default configuration, the overriding applies to only first level in the array.
I want to add parameters to filebrowserImageBrowseRouteParameters but currently I need to redefine all keys of filebrowserImageBrowseRouteParameters in order to make it work

Steps to reproduce

  1. Create a form
use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

class NewsType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('summary',CKEditorType::class, array(
                'required' => false,
                'config_name' => 'admin',
                'config' => [
                    'filebrowserImageBrowseRouteParameters' => [
                        'context' => 'news'
                    ],
                    'filebrowserUploadRouteParameters' => [
                        'context' => 'news'
                    ],
                ]
            ));
    }
}
  1. Define default config:
fos_ck_editor:
    default_config: admin
    configs:
        admin:
            filebrowserBrowseRoute: admin_media_browser
            filebrowserImageBrowseRoute: admin_media_browser
            filebrowserImageBrowseRouteParameters:
                provider: image
                action: browser
            filebrowserUploadMethod: form
            filebrowserUploadRoute: admin_media_upload
            filebrowserUploadRouteParameters:
                provider: image
                action: upload

Expected results

At the end of FOS\CKEditorBundle\Form\Type\CKEditorType::resolveConfig,

$config['filebrowserImageBrowseRouteParameters'] should contain 3 items: provider, action and context

Actual results

$config['filebrowserImageBrowseRouteParameters'] contains only one item: context

The upload does not work in that context.

How to fix

In the file https://github.com/FriendsOfSymfony/FOSCKEditorBundle/blob/2.x/src/Form/Type/CKEditorType.php#L72

Prevously:

$config = array_merge($this->configuration->getConfig($options['config_name']), $config);

Proposal:

$config = array_merge_recursive($this->configuration->getConfig($options['config_name']), $config);

There may be a BC break if that change is made

Regards

@fsoedjede
Copy link
Author

Bad idea. it does not now well. Maybe we can add condition to merge array items?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant