Drupal 11開発ルール
5/28/2025
このルールセットは、Drupal 11開発の包括的なガイドラインを提供し、コードスタイル、命名規則、API使用法、テーマ設定、パフォーマンス、セキュリティ、ドキュメントを網羅しています。Drupal 11 API、Symfonyサービスの使用、Drupalのコーディング標準とベストプラクティスに従うことを重視し、機能的で安全、効率的な開発を確保します。
#cache` metadata in render arrays) for pages and blocks, and consider caching data with Drupal’s Cache API for expensive computations. Minimize database queries by loading entities in bulk (e.g. using `EntityQuery` or `::loadMultiple()` instead of inside loops).
- Use the **Batch API** for long-running processes to avoid timeouts, and offload heavy tasks to queued workers (Queue API or Cron tasks) when appropriate. This keeps the web requests fast and responsive.
- Adhere to Drupal’s update mechanisms: do not directly update the database schema in code – use update hooks (`hook_update_N()`) for any database schema changes to ensure they run during updates. Also, never hack core; always apply changes via modules or themes.
**Documentation and Best Practices**
- Write PHPDoc comments for all classes and functions to document their purpose and usage, following Drupal’s documentation standards. This helps maintain clarity for other developers and for the AI.
- Follow Drupal’s official best practices and coding guidelines in any solution. When in doubt, consult the Drupal 11 documentation or example implementations from Drupal core.
- Provide examples or snippets if they help illustrate a solution (for instance, sample code on how to use a certain Drupal service or API). However, ensure any example code is relevant and tested for Drupal 11 compatibility.
- Keep solutions **modular**. For any new functionality, consider if it belongs in a custom module or can be achieved with an existing contributed module. Recommend established contributed modules (from drupal.org) when appropriate, rather than reinventing the wheel in custom code.