一键导入
drupal-rules
Core Drupal development rules covering code quality, security, services, and testing verification. ALWAYS consult when writing Drupal code.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Core Drupal development rules covering code quality, security, services, and testing verification. ALWAYS consult when writing Drupal code.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use when reviewing Drupal code for standards compliance across PHP, JavaScript, CSS, Twig, YAML, SQL, and markup — dynamically loads relevant standards per file type using Drupal's official community guidelines.
How to write, modify, and style React components for Drupal Canvas and Drupal CMS. Covers the technology stack (React 19, Tailwind CSS 4, CVA variants, cn utility), component.yml prop and slot definitions, enum naming, image and video prop types, formatted text fields, color scheme variants, theme tokens from global.css, required folder structure (index.jsx + component.yml), and matching source site visual styles including extracting design tokens, dark backgrounds, gradient text, glass/blur effects, and updating global.css theme. Use when building, editing, or fixing any component in src/components/.
Managing content in Drupal CMS via JSON:API. Covers listing, fetching, creating, updating, and deleting pages and content entities using npm run content commands. Includes page component structure (uuid, component_id, inputs, parent_uuid, slot), image uploading and media target_id handling, formatted HTML text fields, UUID generation, input format reference mapping component.yml prop types to JSON formats, menu item listing (menu_items--main, menu_items--footer, menu_items--social-media are read-only via API — must use admin UI for create/update/delete), page path alias management, and common pitfalls like wrong media IDs, link props as objects instead of strings, plain strings for HTML fields, target_id as integer instead of string, langcode errors, and JSON:API read-only mode. Use when composing pages, adding components to pages, uploading images, or interacting with the Drupal CMS content API.
Search and fetch Canvas and Drupal CMS documentation pages. Takes a query describing what you need to know (e.g., "code components", "page regions", "known issues", "data fetching") and returns the full content of matching documentation pages. Invoke with /canvas-docs-explorer <query>. Use this whenever you need to understand how Canvas or Drupal CMS works, verify platform behavior, check for limitations, or find configuration options.
Use when setting up a new Drupal CMS project with Canvas for component development. Covers DDEV, JSON:API write mode, Canvas OAuth client, permissions, page regions, menus, project scaffolding, .env, CSS layer fix, and Storybook validation. Every step is idempotent — safe to re-run.
Step-by-step guide for scaffolding a new React component from scratch. Covers copying an existing component as a base, creating the required index.jsx and component.yml files, naming conventions (snake_case machineName, no project prefixes), creating the matching Storybook story file, reusing existing components via imports, composability patterns, and internal component setup (status false). Use when a needed component does not yet exist in src/components/ and must be created.
| name | drupal-rules |
| description | Core Drupal development rules covering code quality, security, services, and testing verification. ALWAYS consult when writing Drupal code. |
Consolidated rules for Drupal development. Follow these for every implementation task.
\Drupal::* static calls in classes..info.yml, .module, /src (PSR-4), .services.yml.config/install/, not hook_install().<module>.services.yml with interface type-hints.final unless explicitly designed for extension.declare(strict_types=1) in all custom PHP files.private > protected > public.Verify Drupal service changes: after service or Twig changes, confirm service injections are correct, DB table and column names exist, and Twig filters actually exist in the project.
*.services.yml file directly.Drupal::hasService("module_name.service_name") before using any service.group_permission) even when docs or module name suggest plural (group_permissions).Xss::filter() or render arrays.Html::escape() for raw HTML output outside Twig.$entity->access('update') returning ALLOWED does NOT mean the route grants access. Other checkers (archived status, custom gates) may still deny.requirements YAML and trace each _*_access* checker class individually..env, settings.local.php, or credential files.Grep the codebase for remaining references after modifying functions, constants, or variables across files. This catches missed locations that would cause runtime errors.
Search for existing config constants before hardcoding values (e.g., * 8 for hours, * 5 for weekdays). Use system-configured values instead.
When removing or disabling something, remove from ALL locations (controller, template, Twig, JS, config) and grep to confirm nothing was missed.
array_filter(), array_map(), array_reduce() over foreach with nested if/break/continue.accessCheck(TRUE) on entity queries — never omit it.#cache metadata (tags, contexts, max-age) to render arrays.->t() or |t in Twig for TranslatableMarkup.\GuzzleHttp\Utils::jsonDecode/jsonEncode (not PHP's json_*).LoggerInterface methods (debug/info/warning/error) -- no custom debug flags.Drupal\my_module\Service) -- use logical groupings.$snake_case for local variables and function parameters.$lowerCamelCase for class properties/attributes..@Then, @Given, @When).Mandatory gate: Run tests, read output, confirm it proves your claim, THEN claim done. Never say "should work", "looks correct", or "I've implemented X" without test output.
# Status code + response size
ddev exec curl -s -o /dev/null -w "%{http_code} %{size_download}" -b <COOKIE> "http://localhost/<PATH>"
# Download full HTML
ddev exec curl -s -b <COOKIE> "http://localhost/<PATH>" > /tmp/page-output.html
# Get auth cookie
ddev drush uli --uid=1 --no-browser 2>/dev/null
Escaping rules: Use Drupal:: not \Drupal:: in single quotes. Use Exception not \Exception. No use statements. Keep PHP on one line.
ddev drush eval 'print json_encode(["exists" => Drupal::hasService("my.service")]);' 2>/dev/null
Store in scripts/tests/. Update scripts/tests/index.md when creating scripts.
These phrases signal unverified claims -- stop and test first:
ddev exec -- write a script file and execute it.drush uli + curl must be in the same script, same shell, with --uri=http://localhost so the cookie domain matches.edit-features, edit-moderation-state-0) not generic machine names.scripts/tests/ directory with index.chmod +x scripts/tests/*.sh.Naming conventions:
verify-{feature}.sh -- feature verification.debug-{feature}-{aspect}.php -- investigation.check-{aspect}.sh -- quick checks.list-{entities}.php -- data listing.fix-{issue}.php -- one-time fixes.