file-browse-upload.rst 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. How to handle file browse/upload
  2. ================================
  3. Before starting, be aware there is nothing which will automatically handle file
  4. browse/upload for you in this bundle (it's out of scope). So, you will need to
  5. implement it by yourself and then configure your browse/upload URIs or routes in
  6. the CKEditor configuration or in the widget.
  7. Supported Options
  8. -----------------
  9. CKEditor natively supports different options according to what you want to
  10. browse or upload. This options should be URIs which point to your controllers.
  11. The available options are:
  12. * filebrowserBrowseUrl
  13. * filebrowserFlashBrowseUrl
  14. * filebrowserImageBrowseUrl
  15. * filebrowserImageBrowseLinkUrl
  16. * filebrowserUploadUrl
  17. * filebrowserFlashUploadUrl
  18. * filebrowserImageUploadUrl
  19. Custom Options
  20. --------------
  21. CKEditor also supports custom options which can be available if you install
  22. plugins. For example, the HTML5 video plugin adds the following options:
  23. * filebrowserVideoBrowseUrl
  24. * filebrowserVideoUploadUrl
  25. To make the bundle aware of these new options, you can configure it globally
  26. in your configuration file:
  27. .. code-block:: yaml
  28. # app/config/config.yml
  29. fos_ck_editor:
  30. filebrowsers:
  31. - VideoBrowse
  32. - VideoUpload
  33. Or you can configure it in your widget:
  34. .. code-block:: php
  35. $builder->add('field', 'ckeditor', array(
  36. 'filebrowsers' => array(
  37. 'VideoUpload',
  38. 'VideoBrowse',
  39. ),
  40. ));
  41. Routing Options
  42. ---------------
  43. To ease the CKEditor file handling, the bundle adds options which are not in
  44. CKEditor by default. These options are related to the Symfony `Routing Component`_
  45. and allow you to configure routes instead of URIs. For each ``*Url`` option,
  46. three new options are available.
  47. For example, the ``filebrowserBrowseUrl`` option can be generated with these
  48. three new options:
  49. * filebrowserBrowseRoute
  50. * filebrowserBrowseRouteParameters
  51. * filebrowserBrowseRouteType
  52. Static Routing
  53. ~~~~~~~~~~~~~~
  54. If your routing is static, you can configure these options globally in your
  55. configuration:
  56. .. code-block:: yaml
  57. # app/config/config.yml
  58. fos_ck_editor:
  59. default_config: my_config
  60. configs:
  61. my_config:
  62. filebrowserBrowseRoute: "my_route"
  63. filebrowserBrowseRouteParameters: { slug: "my-slug" }
  64. filebrowserBrowseRouteType: 0
  65. Or you can configure it your widget:
  66. .. code-block:: php
  67. $builder->add('field', 'ckeditor', array(
  68. 'config' => array(
  69. 'filebrowserBrowseRoute' => 'my_route',
  70. 'filebrowserBrowseRouteParameters' => array('slug' => 'my-slug'),
  71. 'filebrowserBrowseRouteType' => UrlGeneratorInterface::ABSOLUTE_URL,
  72. ),
  73. ));
  74. Dynamic Routing
  75. ~~~~~~~~~~~~~~~
  76. If the static routing does not fit your needs, you can use the
  77. ``filebrowser*Handler`` option allowing you to build your own url with a simple
  78. but much more powerful closure and so make it aware of your dependencies:
  79. .. code-block:: php
  80. // A blog post...
  81. $post = $manager->find($id);
  82. $builder->add('field', 'ckeditor', array(
  83. 'config' => array(
  84. 'filebrowserBrowseHandler' => function (RouterInterface $router) use ($post) {
  85. return $router->generate(
  86. 'my_route',
  87. array('slug' => $post->getSlug()),
  88. UrlGeneratorInterface::ABSOLUTE_URL
  89. );
  90. },
  91. ),
  92. ));
  93. Integration with Other Projects
  94. -------------------------------
  95. If you want to simplify your life, you can directly use other bundles which have
  96. already integrated the concept explain in the previous chapter.
  97. Sonata integration
  98. ~~~~~~~~~~~~~~~~~~
  99. The `CoopTilleulsCKEditorSonataMediaBundle`_ provides a `SonataMedia`_
  100. integration with this bundle.
  101. ELFinder integration
  102. ~~~~~~~~~~~~~~~~~~~~
  103. The `FMElfinderBundle`_ provides a `ELFinder`_ integration with this bundle.
  104. .. _`Routing Component`: http://symfony.com/doc/current/book/routing.html
  105. .. _`CoopTilleulsCKEditorSonataMediaBundle`: https://github.com/coopTilleuls/CoopTilleulsCKEditorSonataMediaBundle
  106. .. _`SonataMedia`: http://sonata-project.org/bundles/media
  107. .. _`FMElfinderBundle`: https://github.com/helios-ag/FMElfinderBundle
  108. .. _`ELFinder`: http://elfinder.org