Skip to content
  • About
    • What is Symfony?
    • Community
    • News
    • Contributing
    • Support
  • Documentation
    • Symfony Docs
    • Symfony Book
    • Screencasts
    • Symfony Bundles
    • Symfony Cloud
    • Training
  • Services
    • SensioLabs Professional services to help you with Symfony
    • Platform.sh for Symfony Best platform to deploy Symfony apps
    • SymfonyInsight Automatic quality checks for your apps
    • Symfony Certification Prove your knowledge and boost your career
    • Blackfire Profile and monitor performance of your apps
  • Other
  • Blog
  • Download
sponsored by SensioLabs
  1. Home
  2. Documentation
  3. Bundles
  4. FOSCKEditorBundle
  5. Customize the toolbar
  • Documentation
  • Book
  • Reference
  • Bundles
  • Cloud

Table of Contents

  • Built-in Toolbars
  • Custom Toolbar

Customize the toolbar

Edit this page

Customize the toolbar

Built-in Toolbars

CKEditor provides three different packages with their own configurations (full, standard & basic). The bundle is shipped with the full edition but you can easily switch the toolbar configuration by using the full, standard or basic keyword as toolbar. You can configure it globally in your configuration:

1
2
3
4
5
# config/packages/fos_ck_editor.yaml
fos_ck_editor:
    configs:
        my_config:
            toolbar: full

Or you can configure it your widget:

1
2
3
$builder->add('field', 'ckeditor', array(
    'config' => array('toolbar' => 'full'),
));

Custom Toolbar

Build a toolbar in the configuration or especially in the widget is really a pain. Each time, you want a custom one, you need to redefine all the structure. To avoid this duplication, the bundle allows you to define your own toolbars or override the built-in ones in a separate node and reuse them. This feature is only available in your configuration.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# config/packages/fos_ck_editor.yaml
fos_ck_editor:
    configs:
        my_config_1:
            toolbar: "my_toolbar_1"
            uiColor: "#000000"
            # ...
        my_config_2:
            toolbar: "my_toolbar_2"
            uiColor: "#ffffff"
            # ...
        my_config_2:
            toolbar: "my_toolbar_1"
            uiColor: "#cccccc"
    toolbars:
        configs:
            my_toolbar_1: [ [ "Source", "-", "Save" ], "/", [ "Anchor" ], "/", [ "Maximize" ] ]
            my_toolbar_2: [ [ "Source" ], "/", [ "Anchor" ], "/", [ "Maximize" ] ]

Here, we see how is structured a toolbar. A toolbar is an array of toolbars (strips), each one being also an array, containing a list of UI items. To do a carriage return, you just have to add the char / between strips. It relies on the exact same structure than CKEditor itself.

Using the toolbars node is better but the config is still not perfect as you still have code duplications in the toolbar items. To avoid this part, you can define a group of items in a separate node & then, inject them in your toolbar by prefixing them with a @.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
fos_ck_editor:
    configs:
        my_config_1:
            toolbar: "my_toolbar_1"
            uiColor: "#000000"
            # ...
        my_config_2:
            toolbar: "my_toolbar_2"
            uiColor: "#ffffff"
            # ...
    toolbars:
        configs:
            my_toolbar_1: [ "@document", "/", "@link" , "/", "@tool" ]
            my_toolbar_2: [ "@document", "/", "@tool" ]
        items:
            document: [ "Source", "-", "Save" ]
            link:     [ "Anchor" ]
            tool:     [ "Maximize" ]

The built-in configurations (full, standard, basic) are also using items so if you want to just override one part of a configuration, just override it:

1
2
3
4
5
6
7
8
fos_ck_editor:
    configs:
        my_config:
            toolbar: "full"
    toolbars:
        items:
            full.colors: [ "TextColor", "BGColor" ]
            full.document: [ "Source", "-", "Preview", "Print" ]

Note

If you want the full list of built-in items, check the `FOS\CKEditorBundle\Config\CKEditorConfiguration` class.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version
    We stand with Ukraine.
    Version:
    Check Code Performance in Dev, Test, Staging & Production

    Check Code Performance in Dev, Test, Staging & Production

    Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).

    Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).

    Symfony footer

    ↓ Our footer now uses the colors of the Ukrainian flag because Symfony stands with the people of Ukraine.

    Avatar of Helmut Hummel, a Symfony contributor

    Thanks Helmut Hummel (@helhum) for being a Symfony contributor

    1 commit • 59 lines changed

    View all contributors that help us make Symfony

    Become a Symfony contributor

    Be an active part of the community and contribute ideas, code and bug fixes. Both experts and newcomers are welcome.

    Learn how to contribute

    Symfony™ is a trademark of Symfony SAS. All rights reserved.

    • What is Symfony?

      • Symfony at a Glance
      • Symfony Components
      • Case Studies
      • Symfony Releases
      • Security Policy
      • Logo & Screenshots
      • Trademark & Licenses
      • symfony1 Legacy
    • Learn Symfony

      • Symfony Docs
      • Symfony Book
      • Reference
      • Bundles
      • Best Practices
      • Training
      • eLearning Platform
      • Certification
    • Screencasts

      • Learn Symfony
      • Learn PHP
      • Learn JavaScript
      • Learn Drupal
      • Learn RESTful APIs
    • Community

      • SymfonyConnect
      • Support
      • How to be Involved
      • Code of Conduct
      • Events & Meetups
      • Projects using Symfony
      • Downloads Stats
      • Contributors
      • Backers
    • Blog

      • Events & Meetups
      • A week of symfony
      • Case studies
      • Cloud
      • Community
      • Conferences
      • Diversity
      • Documentation
      • Living on the edge
      • Releases
      • Security Advisories
      • SymfonyInsight
      • Twig
      • SensioLabs
    • Services

      • SensioLabs services
      • Train developers
      • Manage your project quality
      • Improve your project performance
      • Host Symfony projects

      Deployed on

    Follow Symfony