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

Adding service - yii\base\Module::config() isn't called #24

Closed
MangoMarcus opened this issue Jul 25, 2023 · 1 comment
Closed

Adding service - yii\base\Module::config() isn't called #24

MangoMarcus opened this issue Jul 25, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@MangoMarcus
Copy link

Description

Running php craft make service states to add a method public static function config() to the module in order to register the service as a component, but that method isn't used anywhere by craft

Screenshot 2023-07-25 at 16 11 43

Additional info

  • Craft version: 4.4.16.1
  • PHP version: 8.1.12
@MangoMarcus MangoMarcus added the bug Something isn't working label Jul 25, 2023
@brandonkelly
Copy link
Member

brandonkelly commented Aug 11, 2023

Thanks for reporting that!

It was a bug to recommend adding a config() method there – that’s a plugin-specific feature. Modules are configured via config/app.php. So you should change this:

'modules' => [
    'mymodule' => modules\mymodule\Module::class,
],

to:

'modules' => [
    'mymodule' => [
        'class' => modules\mymodule\Module::class,
        'components' => [
            'myService' => modules\mymodule\services\MyService::class,
        ],
    ],
],

Generator 1.6.0 is out now with a fix for this. Going forward, services that are generated for a module will output this at the end:

Console output at the end of a `craft make service` command for a module, showing that config/app.php should be updated to include the new service component

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants