Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sonata\FormatterBundle\Controller\CkeditorAdminController" has no container set, did you forget to define it as a service subscriber? #669

Closed
t-works opened this issue Jun 4, 2022 · 6 comments
Labels
Milestone

Comments

@t-works
Copy link

t-works commented Jun 4, 2022

Environment

Sonata packages

show

sonata-project/block-bundle              4.13.0          4.13.0          Symfony SonataBlockBundle
sonata-project/cache                     2.2.0           2.2.0           Cache library
Package sonata-project/cache is abandoned, you should avoid using it. No replacement was suggested.
sonata-project/doctrine-extensions       1.17.0          1.17.0          Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 4.3.0           4.3.0           Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                  2.12.0          2.12.0          Lightweight Exporter library
sonata-project/form-extensions           1.16.1          1.16.1          Symfony form extensions
sonata-project/formatter-bundle          5.x-dev e1c640c 5.x-dev e1c640c Symfony SonataFormatterBundle
sonata-project/media-bundle              4.1.5           4.1.5           Symfony SonataMediaBundle
sonata-project/twig-extensions           1.10.0          1.10.0          Sonata twig extensions

Symfony packages

show

symfony/asset                      v6.1.0  v6.1.0  Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files
symfony/cache                      v6.1.0  v6.1.0  Provides an extended PSR-6, PSR-16 (and tags) implementation
symfony/cache-contracts            v3.1.0  v3.1.0  Generic abstractions related to caching
symfony/config                     v6.1.0  v6.1.0  Helps you find, load, combine, autofill and validate configuration values of any kind
symfony/console                    v6.1.0  v6.1.0  Eases the creation of beautiful and testable command line interfaces
symfony/dependency-injection       v6.1.0  v6.1.0  Allows you to standardize and centralize the way objects are constructed in your application
symfony/deprecation-contracts      v3.1.0  v3.1.0  A generic function and convention to trigger deprecation notices
symfony/doctrine-bridge            v6.1.0  v6.1.0  Provides integration for Doctrine with various Symfony components
symfony/dotenv                     v6.1.0  v6.1.0  Registers environment variables from a .env file
symfony/error-handler              v6.1.0  v6.1.0  Provides tools to manage errors and ease debugging PHP code
symfony/event-dispatcher           v6.1.0  v6.1.0  Provides tools that allow your application components to communicate with each other by dispatching events and listening to them
symfony/event-dispatcher-contracts v3.1.0  v3.1.0  Generic abstractions related to dispatching event
symfony/expression-language        v6.1.0  v6.1.0  Provides an engine that can compile and evaluate expressions
symfony/filesystem                 v6.1.0  v6.1.0  Provides basic utilities for the filesystem
symfony/finder                     v6.1.0  v6.1.0  Finds files and directories via an intuitive fluent interface
symfony/flex                       v2.1.8  v2.2.0  Composer plugin for Symfony
symfony/form                       v6.1.0  v6.1.0  Allows to easily create, process and reuse HTML forms
symfony/framework-bundle           v6.1.0  v6.1.0  Provides a tight integration between Symfony components and the Symfony full-stack framework
symfony/http-client                v6.1.0  v6.1.0  Provides powerful methods to fetch HTTP resources synchronously or asynchronously
symfony/http-client-contracts      v3.1.0  v3.1.0  Generic abstractions related to HTTP clients
symfony/http-foundation            v6.1.0  v6.1.0  Defines an object-oriented layer for the HTTP specification
symfony/http-kernel                v6.1.0  v6.1.0  Provides a structured process for converting a Request into a Response
symfony/maker-bundle               v1.43.0 v1.43.0 Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.
symfony/mime                       v6.1.0  v6.1.0  Allows manipulating MIME messages
symfony/options-resolver           v6.1.0  v6.1.0  Provides an improved replacement for the array_replace PHP function
symfony/password-hasher            v6.1.0  v6.1.0  Provides password hashing utilities
symfony/polyfill-intl-grapheme     v1.25.0 v1.26.0 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-icu          v1.25.0 v1.26.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn          v1.25.0 v1.26.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer   v1.25.0 v1.26.0 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring          v1.25.0 v1.26.0 Symfony polyfill for the Mbstring extension
symfony/property-access            v6.1.0  v6.1.0  Provides functions to read and write from/to an object or array using a simple string notation
symfony/proxy-manager-bridge       v6.1.0  v6.1.0  Provides integration for ProxyManager with various Symfony components
symfony/routing                    v6.1.0  v6.1.0  Maps an HTTP request to a set of configuration variables
symfony/runtime                    v6.1.0  v6.1.0  Enables decoupling PHP applications from global state
symfony/security-acl               v3.3.1  v3.3.1  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle            v6.1.0  v6.1.0  Provides a tight integration of the Security component into the Symfony full-stack framework
symfony/security-core              v6.1.0  v6.1.0  Symfony Security Component - Core Library
symfony/security-csrf              v6.1.0  v6.1.0  Symfony Security Component - CSRF Library
symfony/security-http              v6.1.0  v6.1.0  Symfony Security Component - HTTP Integration
symfony/service-contracts          v3.1.0  v3.1.0  Generic abstractions related to writing services
symfony/stopwatch                  v6.1.0  v6.1.0  Provides a way to profile code
symfony/string                     v6.1.0  v6.1.0  Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way
symfony/translation                v6.1.0  v6.1.0  Provides tools to internationalize your application
symfony/translation-contracts      v3.1.0  v3.1.0  Generic abstractions related to translation
symfony/twig-bridge                v6.1.0  v6.1.0  Provides integration for Twig with various Symfony components
symfony/twig-bundle                v6.1.0  v6.1.0  Provides a tight integration of Twig into the Symfony full-stack framework
symfony/validator                  v6.1.0  v6.1.0  Provides tools to validate values
symfony/var-dumper                 v6.1.0  v6.1.0  Provides mechanisms for walking through any arbitrary PHP variable
symfony/var-exporter               v6.1.0  v6.1.0  Allows exporting any serializable PHP data structure to plain PHP code
symfony/web-link                   v6.1.0  v6.1.0  Manages links between resources
symfony/yaml                       v6.1.0  v6.1.0  Loads and dumps YAML files
PS C:\var\projects\stronaklubu2> $ composer show --latest 'sonata-project/*'
$ : The term '$' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try       
again.
At line:1 char:1
+ ~
    + CategoryInfo          : ObjectNotFound: ($:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
PS C:\var\projects\stronaklubu2> composer show --latest 'sonata-project/*'
Info from https://repo.packagist.org: #StandWithUkraine
Color legend:
- patch or minor release available - update recommended
- major release available - update possible
- up to date version
sonata-project/admin-bundle              4.12.0          4.12.0          The missing Symfony Admin Generator
sonata-project/block-bundle              4.13.0          4.13.0          Symfony SonataBlockBundle
sonata-project/cache                     2.2.0           2.2.0           Cache library
Package sonata-project/cache is abandoned, you should avoid using it. No replacement was suggested.
sonata-project/doctrine-extensions       1.17.0          1.17.0          Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 4.3.0           4.3.0           Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                  2.12.0          2.12.0          Lightweight Exporter library
sonata-project/form-extensions           1.16.1          1.16.1          Symfony form extensions
sonata-project/formatter-bundle          5.x-dev e1c640c 5.x-dev e1c640c Symfony SonataFormatterBundle
sonata-project/media-bundle              4.1.5           4.1.5           Symfony SonataMediaBundle
sonata-project/twig-extensions           1.10.0          1.10.0          Sonata twig extensions
PS C:\var\projects\stronaklubu2> composer show --latest 'symfony/*'
Info from https://repo.packagist.org: #StandWithUkraine
Color legend:
- patch or minor release available - update recommended
- major release available - update possible
- up to date version
symfony/asset                      v6.1.0  v6.1.0  Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files
symfony/cache                      v6.1.0  v6.1.0  Provides an extended PSR-6, PSR-16 (and tags) implementation
symfony/cache-contracts            v3.1.0  v3.1.0  Generic abstractions related to caching
symfony/config                     v6.1.0  v6.1.0  Helps you find, load, combine, autofill and validate configuration values of any kind
symfony/console                    v6.1.0  v6.1.0  Eases the creation of beautiful and testable command line interfaces
symfony/dependency-injection       v6.1.0  v6.1.0  Allows you to standardize and centralize the way objects are constructed in your application
symfony/deprecation-contracts      v3.1.0  v3.1.0  A generic function and convention to trigger deprecation notices
symfony/doctrine-bridge            v6.1.0  v6.1.0  Provides integration for Doctrine with various Symfony components
symfony/dotenv                     v6.1.0  v6.1.0  Registers environment variables from a .env file
symfony/error-handler              v6.1.0  v6.1.0  Provides tools to manage errors and ease debugging PHP code
symfony/event-dispatcher           v6.1.0  v6.1.0  Provides tools that allow your application components to communicate with each other by dispatching events and listening to them
symfony/event-dispatcher-contracts v3.1.0  v3.1.0  Generic abstractions related to dispatching event
symfony/expression-language        v6.1.0  v6.1.0  Provides an engine that can compile and evaluate expressions
symfony/filesystem                 v6.1.0  v6.1.0  Provides basic utilities for the filesystem
symfony/finder                     v6.1.0  v6.1.0  Finds files and directories via an intuitive fluent interface
symfony/flex                       v2.1.8  v2.2.0  Composer plugin for Symfony
symfony/form                       v6.1.0  v6.1.0  Allows to easily create, process and reuse HTML forms
symfony/framework-bundle           v6.1.0  v6.1.0  Provides a tight integration between Symfony components and the Symfony full-stack framework
symfony/http-client                v6.1.0  v6.1.0  Provides powerful methods to fetch HTTP resources synchronously or asynchronously
symfony/http-client-contracts      v3.1.0  v3.1.0  Generic abstractions related to HTTP clients
symfony/http-foundation            v6.1.0  v6.1.0  Defines an object-oriented layer for the HTTP specification
symfony/http-kernel                v6.1.0  v6.1.0  Provides a structured process for converting a Request into a Response
symfony/maker-bundle               v1.43.0 v1.43.0 Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.
symfony/mime                       v6.1.0  v6.1.0  Allows manipulating MIME messages
symfony/options-resolver           v6.1.0  v6.1.0  Provides an improved replacement for the array_replace PHP function
symfony/password-hasher            v6.1.0  v6.1.0  Provides password hashing utilities
symfony/polyfill-intl-grapheme     v1.25.0 v1.26.0 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-icu          v1.25.0 v1.26.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn          v1.25.0 v1.26.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer   v1.25.0 v1.26.0 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring          v1.25.0 v1.26.0 Symfony polyfill for the Mbstring extension
symfony/property-access            v6.1.0  v6.1.0  Provides functions to read and write from/to an object or array using a simple string notation
symfony/property-info              v6.1.0  v6.1.0  Extracts information about PHP class' properties using metadata of popular sources
symfony/proxy-manager-bridge       v6.1.0  v6.1.0  Provides integration for ProxyManager with various Symfony components
symfony/routing                    v6.1.0  v6.1.0  Maps an HTTP request to a set of configuration variables
symfony/runtime                    v6.1.0  v6.1.0  Enables decoupling PHP applications from global state
symfony/security-acl               v3.3.1  v3.3.1  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle            v6.1.0  v6.1.0  Provides a tight integration of the Security component into the Symfony full-stack framework
symfony/security-core              v6.1.0  v6.1.0  Symfony Security Component - Core Library
symfony/security-csrf              v6.1.0  v6.1.0  Symfony Security Component - CSRF Library
symfony/security-http              v6.1.0  v6.1.0  Symfony Security Component - HTTP Integration
symfony/serializer                 v6.1.0  v6.1.0  Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML and JSON.
symfony/service-contracts          v3.1.0  v3.1.0  Generic abstractions related to writing services
symfony/stopwatch                  v6.1.0  v6.1.0  Provides a way to profile code
symfony/string                     v6.1.0  v6.1.0  Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way
symfony/translation                v6.1.0  v6.1.0  Provides tools to internationalize your application
symfony/translation-contracts      v3.1.0  v3.1.0  Generic abstractions related to translation
symfony/twig-bridge                v6.1.0  v6.1.0  Provides integration for Twig with various Symfony components
symfony/twig-bundle                v6.1.0  v6.1.0  Provides a tight integration of Twig into the Symfony full-stack framework
symfony/validator                  v6.1.0  v6.1.0  Provides tools to validate values
symfony/var-dumper                 v6.1.0  v6.1.0  Provides mechanisms for walking through any arbitrary PHP variable
symfony/var-exporter               v6.1.0  v6.1.0  Allows exporting any serializable PHP data structure to plain PHP code
symfony/web-link                   v6.1.0  v6.1.0  Manages links between resources
symfony/yaml                       v6.1.0  v6.1.0  Loads and dumps YAML files

PHP version

PHP 8.1.5 (cli) (built: Apr 12 2022 17:38:30) (NTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.1.5, Copyright (c) Zend Technologies
    with Xdebug v3.1.4, Copyright (c) 2002-2022, by Derick Rethans

Subject

Clicking on the Browse Server in FCK editor causer error

Minimal repository with the bug

https://github.com/t-works/sonataFCKeditor_formatter_bug

Steps to reproduce

  1. Navigate to https://127.0.0.1:8000/admin/app/article/create
  2. Click on image icon in FCK editor
  3. Click on Browse Server window with error opens "Sonata\FormatterBundle\Controller\CkeditorAdminController" has no container set, did you forget to define it as a service subscriber?"\
  4. Navigate to upload tab select file and click upload - error message is displayed inline "Sonata\FormatterBundle\Controller\CkeditorAdminController" has no container set, did you forget to define it as a service subscriber?"

Expected results

Have the FCK upload/browse server

Actual results

"Sonata\FormatterBundle\Controller\CkeditorAdminController" has no container set, did you forget to define it as a service subscriber?
ExceptionStack Trace
LogicException
in [project path]vendor\symfony\framework-bundle\Controller\ControllerResolver.php (line 36)
ControllerResolver->instantiateController('Sonata\FormatterBundle\Controller\CkeditorAdminController')
in [project path]vendor\symfony\http-kernel\Controller\ControllerResolver.php (line 109)
ControllerResolver->createController('Sonata\FormatterBundle\Controller\CkeditorAdminController::browserAction')
in [project path]vendor\symfony\http-kernel\Controller\ControllerResolver.php (line 77)
ControllerResolver->getController(object(Request))
in [project path]vendor\symfony\http-kernel\Controller\TraceableControllerResolver.php (line 38)
TraceableControllerResolver->getController(object(Request))
in [project path]vendor\symfony\http-kernel\HttpKernel.php (line 135)
HttpKernel->handleRaw(object(Request), 1)
in [project path]vendor\symfony\http-kernel\HttpKernel.php (line 74)
HttpKernel->handle(object(Request), 1, true)
in [project path]vendor\symfony\http-kernel\Kernel.php (line 202)
Kernel->handle(object(Request))
in [project path]vendor\symfony\runtime\Runner\Symfony\HttpKernelRunner.php (line 35)
HttpKernelRunner->run()
in [project path]vendor\autoload_runtime.php (line 29)
require_once('C:\var\projects\stronaklubu2\vendor\autoload_runtime.php')
in [project path]public\index.php (line 5)

Notes

  1. check in symfony/framework-bundle/Controller/ControllerResolver.php fails because the container is not set in Sonata\FormatterBundle\Controller\CkeditorAdminController

     `if ($controller instanceof ContainerAwareInterface) {
         $controller->setContainer($this->container);
     }
     if ($controller instanceof AbstractController) {
         if (null === $previousContainer = $controller->setContainer($this->container)) {
             throw new \LogicException(sprintf('"%s" has no container set, did you forget to define it as a service subscriber?', $class));
         } else {
             $controller->setContainer($previousContainer);
         }
     }`
    
  2. CkeditorAdminController does not implement ContainerAwareInterface

  3. Container is not injected in any other way during the initialization

  4. I didn't find any information in the sonata formatter docs describing a way or a need to inject container manually

@t-works
Copy link
Author

t-works commented Jun 6, 2022

After adding this to ckeditor.xml the above bug disappears:

        <tag name="container.service_subscriber" />
        <tag name="controller.service_arguments" />
        <call method="setContainer">
            <argument type="service" id="Psr\Container\ContainerInterface"/>
        </call>
    </service>

You may check my fork here:
https://github.com/t-works/SonataFormatterBundle/tree/5.x
I also fixed a number of issues in twig templates that triggered errors with symfony 6 however the upload does not work at the moment - seems that file is not sent with request:
/admin/app/sonatamediamedia/ckeditor_upload?provider=sonata.media.provider.image&context=my-context&format=my-big&CKEditor=s629d71329f98c_body&CKEditorFuncNum=3&langCode=en

@VincentLanglet
Copy link
Member

Indeed, we should add the config similar to MediaBundle:
https://github.com/sonata-project/SonataMediaBundle/blob/4.x/src/Resources/config/controllers.php#L24-L27

Do you want to provide a PR @t-works ?

We should also migrate the config to the php one.
I added this TODO here sonata-project/dev-kit#1715 then we should create a pre-release.

@VincentLanglet VincentLanglet added this to the 5.0 milestone Jun 7, 2022
@t-works
Copy link
Author

t-works commented Jun 10, 2022 via email

@t-works t-works mentioned this issue Jun 11, 2022
Closed
@t-works
Copy link
Author

t-works commented Jun 11, 2022

I had to do some more work to make it functional. Especially in the twig templates. Some lines triggered syntax errors. Also some references to variables in admin object passed to template were incorrect. It appears template was written with phpcr admin in mind (used variables/function calls that exist in phpcr model admin manager but not in ModelManagerInterface and not in SonataDoctrineORMAdminBundle ModelManager)

@jordisala1991
Copy link
Member

jordisala1991 commented Jun 13, 2022

Now the bundle tests browser and upload routes, with functional tests using doctrine orm admin bundle, from 4.4 up to 6.1 versions of Symfony.

Can you check the 5.x-dev (without your PR) on your project to see if everything works?

@jordisala1991
Copy link
Member

Anyway this error should not be reported anymore, let's close this issue and focus on the next problems (if there are any)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants