Drupal Coding Practices
Application skill for Drupal official coding standards ingest (awesome-guidelines). Generic PHP: php-coding-practices. WordPress CMS: wordpress-coding-practices. Accessibility: wcag-accessibility-practices.
Core Principle
Drupal maintainability is always-current handbook discipline plus typed PSR-4 services, two-space layout, module-prefixed procedural code, documented APIs, translatable strings, and PHPCS/PHPStan-enforced conventions across PHP, YAML, Twig, and JS.
When to Use / NOT
- Drupal modules, themes, profiles, and contrib/core-style patches.
- Reviewing
src/, .module, config/*.yml, .html.twig, module JS/CSS.
- Setting up PHPCS Drupal + PHPStan + ESLint in GitLab CI or local dev.
NOT when:
- Non-Drupal PHP,
php-coding-practices.
- WordPress themes/plugins,
wordpress-coding-practices.
- Entity design, routing, or migration architecture, Drupal foundation docs.
- Obsolete drupal.org wiki copies, use GitLab Pages canonical docs.
Workflow
- PHP layout/naming, 2-space, prefixes, casing (
drupal-style-php-naming.md).
- Namespaces/types, PSR-4, use, hints (
drupal-style-namespaces-types.md).
- Documentation/i18n, docblocks, hooks, t() (
drupal-style-documentation-i18n.md).
- Assets/verify, YAML, Twig, JS, CI (
drupal-style-assets-verify.md).
Red Flags
- Tabs in PHP, YAML, CSS, or JS
- Mixed camelCase and snake_case variables in one file
- Procedural function missing module prefix
- Class name containing "Drupal" or "Class" suffix misuse
- Interface/Trait/Test suffix violations
- Closing
?> in module PHP files
else if instead of elseif
- Missing type hints on new public methods
- Undocumented public class method
- Raw English UI string without t()
- Config YAML not prefixed with owning extension
- Twig tag missing trailing
{{ attributes }} when splitting attrs
- JavaScript outside file closure or global variable leak
- PHPCS Drupal or PHPStan failure on changed paths
Verification
phpcs --standard=Drupal (or project ruleset) on changed PHP
- PHPStan at project level on touched
src/ namespaces
- ESLint on changed
.js files (eslint-config-airbnb)
- stylelint on changed CSS where configured
- Docblock spot-check on new hooks/classes
- WCAG checklist on changed UI (
wcag-accessibility-practices)
References
awesome-guidelines/references/drupal-style-learning-note.md
awesome-guidelines/references/drupal-style-php-naming.md
awesome-guidelines/references/drupal-style-namespaces-types.md
awesome-guidelines/references/drupal-style-documentation-i18n.md
awesome-guidelines/references/drupal-style-assets-verify.md
Related skills
php-coding-practices, PSR baseline outside Drupal
wordpress-coding-practices, sibling CMS conventions
wcag-accessibility-practices, accessible Drupal UI
frontend-markup-practices, generic HTML/CSS habits
javascript-coding-practices, JS outside Drupal admin patterns
yaml / config patterns, generic YAML hygiene where applicable
1---2name: drupal-coding-practices3description: Use when authoring or reviewing Drupal modules/themes, 2-space PHP layout, module-prefixed functions, PSR-4 namespaces, docblocks, t() i18n, YAML/Twig/JS standards, and PHPCS/PHPStan verification.4---56# Drupal Coding Practices78Application skill for Drupal official coding standards ingest (`awesome-guidelines`). Generic PHP: `php-coding-practices`. WordPress CMS: `wordpress-coding-practices`. Accessibility: `wcag-accessibility-practices`.910## Core Principle1112Drupal maintainability is **always-current handbook discipline plus typed PSR-4 services**, two-space layout, module-prefixed procedural code, documented APIs, translatable strings, and PHPCS/PHPStan-enforced conventions across PHP, YAML, Twig, and JS.1314## When to Use / NOT1516- Drupal modules, themes, profiles, and contrib/core-style patches.17- Reviewing `src/`, `.module`, `config/*.yml`, `.html.twig`, module JS/CSS.18- Setting up PHPCS Drupal + PHPStan + ESLint in GitLab CI or local dev.1920**NOT when:**2122- Non-Drupal PHP, `php-coding-practices`.23- WordPress themes/plugins, `wordpress-coding-practices`.24- Entity design, routing, or migration architecture, Drupal foundation docs.25- Obsolete drupal.org wiki copies, use GitLab Pages canonical docs.2627## Workflow28291. **PHP layout/naming**, 2-space, prefixes, casing (`drupal-style-php-naming.md`).302. **Namespaces/types**, PSR-4, use, hints (`drupal-style-namespaces-types.md`).313. **Documentation/i18n**, docblocks, hooks, t() (`drupal-style-documentation-i18n.md`).324. **Assets/verify**, YAML, Twig, JS, CI (`drupal-style-assets-verify.md`).3334## Red Flags3536- Tabs in PHP, YAML, CSS, or JS37- Mixed camelCase and snake_case variables in one file38- Procedural function missing module prefix39- Class name containing "Drupal" or "Class" suffix misuse40- Interface/Trait/Test suffix violations41- Closing `?>` in module PHP files42- `else if` instead of `elseif`43- Missing type hints on new public methods44- Undocumented public class method45- Raw English UI string without t()46- Config YAML not prefixed with owning extension47- Twig tag missing trailing `{{ attributes }}` when splitting attrs48- JavaScript outside file closure or global variable leak49- PHPCS Drupal or PHPStan failure on changed paths5051## Verification5253- `phpcs --standard=Drupal` (or project ruleset) on changed PHP54- PHPStan at project level on touched `src/` namespaces55- ESLint on changed `.js` files (eslint-config-airbnb)56- stylelint on changed CSS where configured57- Docblock spot-check on new hooks/classes58- WCAG checklist on changed UI (`wcag-accessibility-practices`)596061## References6263- `awesome-guidelines/references/drupal-style-learning-note.md`64- `awesome-guidelines/references/drupal-style-php-naming.md`65- `awesome-guidelines/references/drupal-style-namespaces-types.md`66- `awesome-guidelines/references/drupal-style-documentation-i18n.md`67- `awesome-guidelines/references/drupal-style-assets-verify.md`6869## Related skills7071- `php-coding-practices`, PSR baseline outside Drupal72- `wordpress-coding-practices`, sibling CMS conventions73- `wcag-accessibility-practices`, accessible Drupal UI74- `frontend-markup-practices`, generic HTML/CSS habits75- `javascript-coding-practices`, JS outside Drupal admin patterns76- `yaml` / config patterns, generic YAML hygiene where applicable