跳到内容

从 IvoryCKEditorBundle 迁移到 FOSCKEditorBundle

编辑此页

这里我们将解释迁移过程。

概要:查看我们如何迁移 SonataFormatterBundle

更新 composer.json

1
2
composer remove egeloen/ckeditor-bundle
composer require friendsofsymfony/ckeditor-bundle

更新 bundle 定义

替换

1
2
3
4
5
6
<?php

// config/bundles.php
return [
    Ivory\CKEditorBundle\IvoryCKEditorBundle::class => ['all' => true],
];

替换为

1
2
3
4
5
6
<?php

// config/bundles.php
return [
    FOS\CKEditorBundle\FOSCKEditorBundle::class => ['all' => true],
];

如果您没有使用 Symfony Flex,请在您的 AppKernel 中替换这个。

替换

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php

// app/AppKernel.php

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            new Ivory\CKEditorBundle\IvoryCKEditorBundle(),
            // ...
        ];

        // ...
    }
}

替换为

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php

// app/AppKernel.php

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            new FOS\CKEditorBundle\FOSCKEditorBundle(),
            // ...
        ];

        // ...
    }
}

更新配置根键

只有配置的根键被更改了。

替换

1
2
3
4
5
6
7
8
9
10
# config/packages/ivory_ck_editor.yaml

ivory_ck_editor:
    configs:
        my_config:
            toolbar: [ ["Source", "-", "Save"], "/", ["Anchor"], "/", ["Maximize"] ]
            uiColor:                "#000000"
            filebrowserUploadRoute: "my_route"
            extraPlugins:           "wordcount"
            # ...

替换为

1
2
3
4
5
6
7
8
9
10
# config/packages/fos_ck_editor.yaml

fos_ck_editor:
    configs:
        my_config:
            toolbar: [ ["Source", "-", "Save"], "/", ["Anchor"], "/", ["Maximize"] ]
            uiColor:                "#000000"
            filebrowserUploadRoute: "my_route"
            extraPlugins:           "wordcount"
            # ...

如果您没有使用 Symfony Flex,请在 app/config/config.yml 中替换根键。

替换

1
2
3
4
5
6
7
8
9
# app/config/config.yml
ivory_ck_editor:
    configs:
        my_config:
            toolbar: [ ["Source", "-", "Save"], "/", ["Anchor"], "/", ["Maximize"] ]
            uiColor:                "#000000"
            filebrowserUploadRoute: "my_route"
            extraPlugins:           "wordcount"
            # ...

替换为

1
2
3
4
5
6
7
8
9
# app/config/config.yml
fos_ck_editor:
    configs:
        my_config:
            toolbar: [ ["Source", "-", "Save"], "/", ["Anchor"], "/", ["Maximize"] ]
            uiColor:                "#000000"
            filebrowserUploadRoute: "my_route"
            extraPlugins:           "wordcount"
            # ...

更新命名空间

主要的变化是命名空间,所以您将需要在您的应用程序中找到所有出现 Ivory\CKEditorBundle\* 的地方,并将它们替换为 FOS\CKEditorBundle\*

之前

1
2
3
4
5
<?php

use Ivory\CKEditorBundle\Form\Type\CKEditorType;

$form->add('body',  CKEditorType::Class)

之后

1
2
3
4
5
<?php

use FOS\CKEditorBundle\Form\Type\CKEditorType;

$form->add('body',  CKEditorType::Class)

更新服务定义

如果您直接从容器中获取任何服务,您将需要在您的应用程序中找到所有出现 ivory_ck_editor.* 的地方,并将它们替换为 fos_ck_editor.*

而不是这样做

1
$this->get('ivory_ck_editor.form.type');

您应该这样做

1
$this-get('fos_ck_editor.form.type');

重新生成 assets

首先获取 ckeditor assets

1
bin/console ckeditor:install

然后重新生成 Symfony assets

1
bin/console assets:install
这项工作,包括代码示例,根据 Creative Commons BY-SA 3.0 许可协议获得许可。
目录
    版本