drupaldrupal-modules

Class Drupal\twig_tweak\Twig_Extension not found in Drupal 10


I'm developing a website on Drupal 10 and I need the module Twig Tweak to be installed and working in order to use drupal_entity() in templates.

I copy-pasted the module from the /modules directory of another website powered by Drupal 8.9 and changed the line core: 8.x in the twig_tweak.info.yml file to core_version_requirement: ^10

But when I run the new website powered by Drupal 10 on the browser I receive the error

Class "Drupal\twig_tweak\Twig_Extension" not found in include() ...

This error is not thrown on Drupal 8 and 9 - only in Drupal 10.

How to resolve the issue?


Solution

  • The version of the module you are using is incompatible with Drupal 10. Some methods get deprecated, so the core compatibility strategy (update only the yml files) will not work for all cases.

    You should download the module via composer

    composer require drupal/twig_tweak
    

    This is the recommended way to work with contrib modules. If you have any custom code on it, you should patch it.

    Here is some info about patches

    https://www.drupal.org/docs/develop/git/using-git-to-contribute-to-drupal/working-with-patches/making-a-patch

    If somehow you can't use composer, try to download it from the module page. And check the core compatibility.

    https://www.drupal.org/project/twig_tweak