Problem/Motivation

The website encountered an unexpected error. Try again later.

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "Drupal\classy\Hook\ClassyHooks". in Drupal\Component\DependencyInjection\Container->get() (line 159 of core/lib/Drupal/Component/DependencyInjection/Container.php). 

\Drupal\Core\DrupalKernel::discoverServiceProviders skippes themes.

Steps to reproduce

Update to release 2.0.1 and open the page.

Proposed resolution

Remove services.yml and use the class directly.

Remaining tasks

-

User interface changes

-

API changes

-

Data model changes

-

Issue fork classy-3600782

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tobiasb created an issue. See original summary.

tobiasb’s picture

Title: Fix OOP-Hooks » ServiceNotFoundException: You have requested a non-existent service "Drupal\classy\Hook\ClassyHooks"

tobiasb’s picture

Assigned: tobiasb » Unassigned
Status: Active » Needs review
tobiasb’s picture

smustgrave’s picture

Just tried replicating and not getting any error.

Also would expect the tests to be failing if it caused fatal errors?

tobiasb’s picture

The tests are running with D11, and the hooks in classy.theme are not called. Main problem is only in d10.

With d10:

PHPUnit 9.6.34 by Sebastian Bergmann and contributors.

Testing /var/www/html/web/themes/contrib/classy/tests
Classy (Drupal\Tests\classy\Functional\Classy)
 ✘ Regression missing messages css
   │
   │ Behat\Mink\Exception\ExpectationException: Current response status code is 500, but 200 expected.
   │
   │ /var/www/html/vendor/behat/mink/src/WebAssert.php:888
   │ /var/www/html/vendor/behat/mink/src/WebAssert.php:145
   │ /var/www/html/web/themes/contrib/classy/tests/src/Functional/ClassyTest.php:26
   │ /var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:729
   │

Classy (Drupal\Tests\classy\Kernel\Classy)
 ✔ Classy theme

Time: 00:02.903, Memory: 10.00 MB

Summary of non-successful tests:

Classy (Drupal\Tests\classy\Functional\Classy)
 ✘ Regression missing messages css
   │
   │ Behat\Mink\Exception\ExpectationException: Current response status code is 500, but 200 expected.
   │
   │ /var/www/html/vendor/behat/mink/src/WebAssert.php:888
   │ /var/www/html/vendor/behat/mink/src/WebAssert.php:145
   │ /var/www/html/web/themes/contrib/classy/tests/src/Functional/ClassyTest.php:26
   │ /var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:729
   │

ERRORS!
Tests: 2, Assertions: 3, Errors: 1.
tobiasb’s picture

Oh this would also break in Drupal core < v11.3. because the support for theme oop hooks was added there https://www.drupal.org/node/3551652.

smustgrave’s picture

Can we use a deprecation helper vs deleting the service?

smustgrave’s picture

Something like that? Thoughts?

tobiasb’s picture

The file is never loaded. I created also a https://www.drupal.org/project/rector/issues/3600784.

\Drupal\Core\DrupalKernel::discoverServiceProviders only supports modules.

solideogloria’s picture

Priority: Normal » Critical

This causes a fatal error site-wide wherever the theme is applied. Bumping to Critical.

solideogloria’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

maheshv’s picture

We tested this in our local environment using Drupal 10.6.10, and it is working fine. We are not encountering any issues related to this.

smustgrave’s picture

Will take a look tomorrow but not overly a fan of reverting this to just calling the class

smustgrave’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

smustgrave’s picture

Thanks everyone just did a new tag