PacktPublishing / Drupal-9-Module-Development-Third-Edition

Drupal 9 Module Development, published by Packt
69 stars 50 forks source link

Error: Class "Drupal\hello_world\SalutationEvent" not found in Drupal\hello_world\HelloWorldSalutation… #7

Closed bisonbleu closed 1 year ago

bisonbleu commented 1 year ago

How to reproduce:

The detailed error:

The website encountered an unexpected error. Please try again later. Error: Class "Drupal\hello_world\SalutationEvent" not found in Drupal\hello_world\HelloWorldSalutation->getSalutation() (line 53 of modules/custom/hello_world/src/HelloWorldSalutation.php).

Drupal\hello_world\HelloWorldSalutation->getSalutation() (Line: 48) Drupal\hello_world\Controller\HelloWorldController->helloWorld() call_user_func_array(Array, Array) (Line: 123) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber{closure}() (Line: 564) Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber{closure}() (Line: 159) Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81) Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58) Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48) Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106) Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85) Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48) Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51) Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23) Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709) Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

bisonbleu commented 1 year ago

The same error occurs with chapter3 and chapter4 code…

Could this be related to the Note at the bottom of page 63 ?

At the time of writing, Drupal is still using deprecated code from the Symfony Event Dispatcher, which in version 4.3 has changed the signature of the EventDispatcherInterface::dispatch() method, as well as having introduced a different base Event class. Until Drupal makes this change as well, we will continue to use the deprecated code.

bisonbleu commented 1 year ago

RESOLVED - the code from this repo is correct. The issue is that I was using the book's code excerpt on page 63 where there's an error. See capture. Screen Shot 2022-11-17 at 11 40 35 AM

bisonbleu commented 1 year ago

Closing this ticket, «works as designed».