Loading...
Loading...
Craft CMS 5 plugin and module development — extending Craft. Covers the full extend surface: elements, element queries, services, models, records, project config, controllers, CP templates, migrations, queue jobs, console commands, field types, native fields, events, behaviors, Twig extensions, utilities, widgets, filesystems, debugging, testing, and GraphQL. Triggers on: beforePrepare(), afterSave(), defineSources(), defineTableAttributes(), attributeHtml(), MemoizableArray, getConfig(), handleChanged, $allowAnonymous, $enableCsrfValidation, BaseNativeField, EVENT_DEFINE_NATIVE_FIELDS, FieldLayoutBehavior, EVENT_REGISTER, EVENT_DEFINE, EVENT_BEFORE, EVENT_AFTER, CraftVariable, registerTwigExtension, DefineConsoleActionsEvent, PHPStan, Pest. Always use when writing, editing, or reviewing any Craft CMS plugin or module code.
npx skill4agent add michtio/craftcms-claude-skills craftcmscraft-sitecraft-php-guidelinesweb_fetchaddSelect()beforePrepare()->site('*')idgetConfig()DateTimeHelperCarbonelements.mdelement-index.mdfields.mdmigrations.mdcontrollers.mdevents.mdqueue-jobs.mdelements.mddebugging.mdcontrollers.mdcp.mdarchitecture.mdfields.mdevents.mdquality.mdevents.mdevents.mdevents.mdevents.mdcp.md| Task | Read |
|---|---|
| Element core: lifecycle, queries, status, authorization, drafts, revisions, propagation, field layouts, events | |
| Element index: sources, table/card attributes, sort, conditions, actions, exporters, sidebar, metadata | |
| Services, models, records, project config, MemoizableArray, events, API clients, custom validators | |
| Controllers: CP CRUD, webhooks, API endpoints, action routing, authorization | |
| CP templates, form macros, admin changes, VueAdminTable, asset bundles, CP layout, permissions | |
| Database migrations, Install.php, foreign keys, indexes, idempotency, deployment | |
| Queue jobs, BaseJob, TTR, retry, progress, batch jobs, site context | |
| Console commands, arguments, options, progress bars, output helpers, resave actions | |
| Debugging, performance, query strategy, profiling, Xdebug, caching, logging | |
| PHPStan, Pest testing, code review checklist | |
| Field types, native fields, BaseNativeField, field layout elements, FieldLayoutBehavior | |
| Events: registration, lifecycle, naming conventions, custom events, behaviors, Twig extensions, utilities, widgets, filesystems, discovering events | |
| GraphQL types, queries, mutations, directives, schema components, resolvers | |
| Feature | Plugin | Module |
|---|---|---|
| CP template root | Automatic (by handle) | Manual via |
| Site template root | Manual via event | Same — manual for both |
| Translation category | Automatic (by handle) | Manual |
| Settings model | Built-in | Env vars, config files, or private plugin ( |
| Install migration | | Content migrations only |
| Console commands | Automatic | Must set before |
| CP nav section | | |
| Project config | Settings auto-tracked | Manual |
| Namespace alias | Automatic via Composer | Must call |
use craft\events\RegisterTemplateRootsEvent;
use craft\web\View;
Event::on(View::class, View::EVENT_REGISTER_CP_TEMPLATE_ROOTS,
function(RegisterTemplateRootsEvent $event) {
$event->roots['my-module'] = __DIR__ . '/templates';
}
);Craft::$app->i18n->translations['my-module'] = [
'class' => \craft\i18n\PhpMessageSource::class,
'sourceLanguage' => 'en',
'basePath' => __DIR__ . '/translations',
'allowOverrides' => true,
];public function init()
{
Craft::setAlias('@mymodule', __DIR__);
if (Craft::$app->getRequest()->getIsConsoleRequest()) {
$this->controllerNamespace = 'modules\\mymodule\\console\\controllers';
} else {
$this->controllerNamespace = 'modules\\mymodule\\controllers';
}
parent::init(); // MUST come after setting controllerNamespace
}config/app.php