2

I'm expanding my Craft website with a small Module, internal to this project. The module currently only defines a new input-field (extending craft\base\Field).

I have dumped the autoloader from composer and my config/app.php only contains the registration of this module:

<?php
return [
    'modules' => [
        'simple-markdown-editor' => [
            'class' => \codeisland\simplemde\MarkdownModule::class,
        ],
    ],
    'bootstrap' => ['simple-markdown-editor'],
];

This setup works and the new field shows up in the Admin CP. But: as far as I understand the bootstrap-entry, it's only needed if the module needs to be executed on every page render. The Craft documentation says as much:

TIP: If your module doesn’t need to get loaded on every request, you can remove its ID from the bootstrap array.

Since the module only defines an input-field for the Admin CP, it doesn't need to be loaded on every request. But if I remove it from the bootstrap-array, it's not loaded at all.

Do I need to add additional config? Or am I just misunderstanding the documentation?

  • I’ve experienced this too. Curious to know if this is a bug, a documentation error, or if there is some legitimate workaround. – Lindsey D Jun 15 '19 at 16:20
2

It does in fact need to be loaded on every request, because otherwise your EVENT_REGISTER_FIELD_TYPES event listener wouldn’t get registered, which is responsible for telling Craft that the field type exists.

| improve this answer | |
  • This makes sense, thanks for the feedback. Is there a rule of thumb on when it's save to not put the module in the bootstrap-array? – Lukas Knuth Jun 17 '19 at 22:05
  • Yeah, when your module isn’t doing anything special in init(). – Brandon Kelly Jun 17 '19 at 23:56
  • "special" meaning not registering anything via Event? – Lukas Knuth Jun 19 '19 at 14:19
  • That’s one example, yes. – Brandon Kelly Jun 19 '19 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.