FriendsOfSymfony / FOSCKEditorBundle

Provides a CKEditor integration for your Symfony project.
Other
518 stars 83 forks source link

CKEditor script path is affected by framework.assets.base_path #181

Closed TomaszGasior closed 5 years ago

TomaszGasior commented 5 years ago

…and I'm not sure whether it should.

Environment

Symfony packages

symfony/asset                v4.2.4  v4.2.4  Symfony Asset Component
symfony/browser-kit          v4.2.4  v4.2.4  Symfony BrowserKit Component
symfony/cache                v4.2.4  v4.2.4  Symfony Cache component with PSR-6, PSR-16, and tags
symfony/config               v4.2.4  v4.2.4  Symfony Config Component
symfony/console              v4.2.4  v4.2.4  Symfony Console Component
symfony/contracts            v1.0.2  v1.0.2  A set of abstractions extracted out of the Symfony comp...
symfony/css-selector         v4.2.4  v4.2.4  Symfony CssSelector Component
symfony/debug                v4.2.4  v4.2.4  Symfony Debug Component
symfony/debug-bundle         v4.2.4  v4.2.4  Symfony DebugBundle
symfony/dependency-injection v4.2.4  v4.2.4  Symfony DependencyInjection Component
symfony/doctrine-bridge      v4.2.4  v4.2.4  Symfony Doctrine Bridge
symfony/dom-crawler          v4.2.4  v4.2.4  Symfony DomCrawler Component
symfony/dotenv               v4.2.4  v4.2.4  Registers environment variables from a .env file
symfony/event-dispatcher     v4.2.4  v4.2.4  Symfony EventDispatcher Component
symfony/expression-language  v4.2.4  v4.2.4  Symfony ExpressionLanguage Component
symfony/filesystem           v4.2.4  v4.2.4  Symfony Filesystem Component
symfony/finder               v4.2.4  v4.2.4  Symfony Finder Component
symfony/flex                 v1.2.0  v1.2.0  Composer plugin for Symfony
symfony/form                 v4.2.4  v4.2.4  Symfony Form Component
symfony/framework-bundle     v4.2.4  v4.2.4  Symfony FrameworkBundle
symfony/http-foundation      v4.2.4  v4.2.4  Symfony HttpFoundation Component
symfony/http-kernel          v4.2.4  v4.2.4  Symfony HttpKernel Component
symfony/inflector            v4.2.4  v4.2.4  Symfony Inflector Component
symfony/intl                 v4.2.4  v4.2.4  A PHP replacement layer for the C intl extension that i...
symfony/maker-bundle         v1.11.5 v1.11.5 Symfony Maker helps you create empty commands, controll...
symfony/monolog-bridge       v4.2.4  v4.2.4  Symfony Monolog Bridge
symfony/monolog-bundle       v3.3.1  v3.3.1  Symfony MonologBundle
symfony/options-resolver     v4.2.4  v4.2.4  Symfony OptionsResolver Component
symfony/phpunit-bridge       v4.2.4  v4.2.4  Symfony PHPUnit Bridge
symfony/polyfill-intl-icu    v1.11.0 v1.11.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn    v1.11.0 v1.11.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf...
symfony/polyfill-mbstring    v1.11.0 v1.11.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php72       v1.11.0 v1.11.0 Symfony polyfill backporting some PHP 7.2+ features to ...
symfony/process              v4.2.4  v4.2.4  Symfony Process Component
symfony/profiler-pack        v1.0.4  v1.0.4  A pack for the Symfony web profiler
symfony/property-access      v4.2.4  v4.2.4  Symfony PropertyAccess Component
symfony/routing              v4.2.4  v4.2.4  Symfony Routing Component
symfony/security-bundle      v4.2.4  v4.2.4  Symfony SecurityBundle
symfony/security-core        v4.2.4  v4.2.4  Symfony Security Component - Core Library
symfony/security-csrf        v4.2.4  v4.2.4  Symfony Security Component - CSRF Library
symfony/security-guard       v4.2.4  v4.2.4  Symfony Security Component - Guard
symfony/security-http        v4.2.4  v4.2.4  Symfony Security Component - HTTP Integration
symfony/stopwatch            v4.2.4  v4.2.4  Symfony Stopwatch Component
symfony/swiftmailer-bundle   v3.2.5  v3.2.5  Symfony SwiftmailerBundle
symfony/twig-bridge          v4.2.4  v4.2.4  Symfony Twig Bridge
symfony/twig-bundle          v4.2.4  v4.2.4  Symfony TwigBundle
symfony/validator            v4.2.4  v4.2.4  Symfony Validator Component
symfony/var-dumper           v4.2.4  v4.2.4  Symfony mechanism for exploring and dumping PHP variables
symfony/var-exporter         v4.2.4  v4.2.4  A blend of var_export() + serialize() to turn any seria...
symfony/web-profiler-bundle  v4.2.4  v4.2.4  Symfony WebProfilerBundle
symfony/web-server-bundle    v4.2.4  v4.2.4  Symfony WebServerBundle
symfony/yaml                 v4.2.4  v4.2.4  Symfony Yaml Component

Subject

My context: I don't use Webpack encore and "/assets" directory. Instead, my CSS and JS files are placed directly in "/public/assets". For convenience I added framework.asset.base_path with value "assets" to make using asset() function in Twig templates simpler.

For some reason, FOSCKEditorBundle uses path specified in "framework.assets.base_path" to generate its own path to JS files of CKEditor. So, this bundle tries to load CKEditor from URL /assets/bundles/fosckeditor/ckeditor.js instead from URL /bundles/fosckeditor/ckeditor.js.

Steps to reproduce

  1. Set framework.asset.base_path in framework.yaml to some value, "assets" for example.
  2. Use this bundle: try to use CKEditor widget in forms.

Expected results

CKEditor should be loaded from URL `/bundles/fosckeditor/ckeditor.js' by default.

Actual results

JS file path is affected by framework.assets.base_path setting. Even with 'base_path' set in bundle config, path is affected by that setting.

My current workaround:

fos_ck_editor:
    base_path: '../bundles/fosckeditor'
    js_path:   '../bundles/fosckeditor/ckeditor.js'
TomaszGasior commented 5 years ago

This is source of my problem: https://github.com/FriendsOfSymfony/FOSCKEditorBundle/blob/2.x/src/Renderer/CKEditorRenderer.php#L268

What is the reason of using asset package to generate URL?

kunicmarko20 commented 5 years ago

How else is it supposed to get the urls? The assets path should point to your assets, not sure if this is valid since I never saw a complain around this

TomaszGasior commented 5 years ago

For me this is not intuitive but I checked 7 various bundles with src/Resources/public, only one of them append assets automatically (do not require to do it manually) — it's sonata admin bundle and its doing this the same way as FOSCKEditorBundle.

Maybe it might be useful to allow users to set custom asset package. In my case I am going to create my own assets package and keep default asset package for bundles only.

kunicmarko20 commented 5 years ago

If you have an idea and can make it in a BC way, I will be glad to merge it.