Search code examples
phpsymfonytwigcomposer-phpdowngrade

Downgrading Twig: Uncaught Error: Call to undefined method Twig\Environment


I'm using Symfony 4.4 on a project and I need to use stfalcontinymce. Since I'm on SF4 I need the version 2.4. So I did this:

composer require stfalcon/tinymce-bundle=2.4

But then I get this error:

!!  11:03:44 CRITICAL  [php] Uncaught Error: Class 'Twig_Extension' not found ["exception" => Error { …}]
!!
!!  In StfalconTinymceExtension.php line 13:
!!                                                                        
!!    Attempted to load class "Twig_Extension" from the global namespace. 
!!    Did you forget a "use" statement? 

Someone told me that it's because this version doesn't get along with Twig 3 so I need to downgrade my Twig version. I then did this to downgrade Twig:

composer require twig/twig=2

But then I get this error:

     13:14:07 CRITICAL  [php] Uncaught Error: Call to undefined method Twig\Environment::registerUndefinedTokenPa
rserCallback() ["exception" => Error { …}]
!!
!!  In srcApp_KernelDevDebugContainer.php line 2040:
!!  
!!    Attempted to call an undefined method named "registerUndefinedTokenParserCallback" of class "Twig\Environm ent".
!!    Did you mean to call e.g. "registerUndefinedFilterCallback" or "registerUndefinedFunctionCallback"?

I tried adding in composer.json

"twig/extensions": "*"

Then composer install, then running the command:

composer require stfalcon/tinymce-bundle=2.4 -W

And I get this error:

!!  13:49:04 CRITICAL  [php] Uncaught Error: Call to undefined method 

Twig\Environment::registerUndefinedTokenParserCallback() ["exception" => Error { …}]
!!
!!  In srcApp_KernelDevDebugContainer.php line 2045:
!!  
!!    Attempted to call an undefined method named "registerUndefinedTokenParserCallback" of class "Twig\Environment".
!!    Did you mean to call e.g. "registerUndefinedFilterCallback" or "registerUndefinedFunctionCallback"?

I'm really lost here. Can someone help? thanks


Solution

  • Your executed commands don't seem to be possible on my system at all since there will be version constraint conflicts.

    Instead of restricting to one version for your dependencies, you should use a constraint.

    Your require in composer.json may contain something like the following

            "twig/twig": "^2",
            "stfalcon/tinymce-bundle": "2.4.*",
            "twig/extra-bundle": "^2"
    

    The constraints are explained here. But the ^2 basically means >= 2.x.x and < 3.0.0

    For the tinymce bundle I used the above because of the this GitHub issue

    Furthermore twig/extensions seems to be deprecated, and this GitHub issue mentions twig/extra-bundle which is needed and may be its replacement.