toolbar.rst 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. Customize the toolbar
  2. =====================
  3. Built-in Toolbars
  4. -----------------
  5. CKEditor provides three different packages with their own configurations (full,
  6. standard & basic). The bundle is shipped with the full edition but you can
  7. easily switch the toolbar configuration by using the ``full``, ``standard`` or
  8. ``basic`` keyword as toolbar. You can configure it globally in your configuration:
  9. .. code-block:: yaml
  10. # config/packages/fos_ck_editor.yaml
  11. fos_ck_editor:
  12. configs:
  13. my_config:
  14. toolbar: full
  15. Or you can configure it your widget:
  16. .. code-block:: php
  17. $builder->add('field', 'ckeditor', array(
  18. 'config' => array('toolbar' => 'full'),
  19. ));
  20. Custom Toolbar
  21. --------------
  22. Build a toolbar in the configuration or especially in the widget is really a
  23. pain. Each time, you want a custom one, you need to redefine all the structure.
  24. To avoid this duplication, the bundle allows you to define your own toolbars or
  25. override the built-in ones in a separate node and reuse them. This feature is
  26. only available in your configuration.
  27. .. code-block:: yaml
  28. # config/packages/fos_ck_editor.yaml
  29. fos_ck_editor:
  30. configs:
  31. my_config_1:
  32. toolbar: "my_toolbar_1"
  33. uiColor: "#000000"
  34. # ...
  35. my_config_2:
  36. toolbar: "my_toolbar_2"
  37. uiColor: "#ffffff"
  38. # ...
  39. my_config_2:
  40. toolbar: "my_toolbar_1"
  41. uiColor: "#cccccc"
  42. toolbars:
  43. configs:
  44. my_toolbar_1: [ [ "Source", "-", "Save" ], "/", [ "Anchor" ], "/", [ "Maximize" ] ]
  45. my_toolbar_2: [ [ "Source" ], "/", [ "Anchor" ], "/", [ "Maximize" ] ]
  46. Here, we see how is structured a toolbar. A toolbar is an array of toolbars
  47. (strips), each one being also an array, containing a list of UI items. To do a
  48. carriage return, you just have to add the char ``/`` between strips. It relies
  49. on the exact same structure than CKEditor itself.
  50. Using the toolbars node is better but the config is still not perfect as you
  51. still have code duplications in the toolbar items. To avoid this part, you can
  52. define a group of items in a separate node & then, inject them in your toolbar
  53. by prefixing them with a ``@``.
  54. .. code-block:: yaml
  55. fos_ck_editor:
  56. configs:
  57. my_config_1:
  58. toolbar: "my_toolbar_1"
  59. uiColor: "#000000"
  60. # ...
  61. my_config_2:
  62. toolbar: "my_toolbar_2"
  63. uiColor: "#ffffff"
  64. # ...
  65. toolbars:
  66. configs:
  67. my_toolbar_1: [ "@document", "/", "@link" , "/", "@tool" ]
  68. my_toolbar_2: [ "@document", "/", "@tool" ]
  69. items:
  70. document: [ "Source", "-", "Save" ]
  71. link: [ "Anchor" ]
  72. tool: [ "Maximize" ]
  73. The built-in configurations (full, standard, basic) are also using items so if
  74. you want to just override one part of a configuration, just override it:
  75. .. code-block:: yaml
  76. fos_ck_editor:
  77. configs:
  78. my_config:
  79. toolbar: "full"
  80. toolbars:
  81. items:
  82. full.colors: [ "TextColor", "BGColor" ]
  83. full.document: [ "Source", "-", "Preview", "Print" ]
  84. .. note::
  85. If you want the full list of built-in items, check the
  86. `FOS\\CKEditorBundle\\Config\\CKEditorConfiguration` class.