drupal-form-alter

Modify Drupal forms via hook_form_alter to tailor fields, validation, and submission.

67|13|Updated Apr 15, 2026
One-click install
npx skills add https://github.com/edutrul/drupal-ai --skill drupal-form-alter
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: drupal-form-alter
Source: https://github.com/edutrul/drupal-ai/tree/main/.claude/skills/drupal-form-alter
Command: npx skills add https://github.com/edutrul/drupal-ai --skill drupal-form-alter

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Modifying Drupal forms can require invasive changes; this skill provides a structured pattern to apply hook_form_alter and hook_form_FORM_ID_alter to adjust fields, access controls, and submission handling in a safe, repeatable way.

Core Features & Use Cases

  • Combines OOP hooks and procedural hooks for Drupal 10.3+/11 to apply form alterations.
  • Common alterations include hiding fields, changing required/default values, and attaching validators or submit handlers.
  • Get the Form Object from FormState to access and modify the underlying entity during the alteration process.

Quick Start

Create a MyModuleHooks class and implement formAlter to modify a specific form (e.g., node_article_form) by adding a custom validate handler and a submit handler.

Frequently Asked Questions about drupal-form-alter

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I modify Drupal forms to hide fields or change default values?

Use hook_form_alter or hook_form_FORM_ID_alter to declaratively adjust fields, change required/default values, and hide elements safely across node and config forms.

How do I add custom validation and submit handlers to a Drupal node form?

Add custom validation and submit handlers to a Drupal node form by implementing form alter hooks to attach your custom logic to the form array and FormStateInterface.

Does this form alter approach work with Drupal 10.3 and 11 OOP hooks?

Yes, this approach works with Drupal 10.3+ and 11 by combining OOP hooks and procedural hooks to apply safe, testable form alterations.

When do I need hook_form_alter vs hook_form_FORM_ID_alter?

Use hook_form_alter for broad modifications across multiple forms, and hook_form_FORM_ID_alter to target a specific form ID like node_article_form for precise alterations.

How do I access the underlying entity during a Drupal form alteration?

Retrieve the Form Object from FormStateInterface during the alteration process to access and modify the underlying entity properties safely.