drupal-form-api
Skill71 starsChanged 7 months agoMITView on GitHub
Drupal Form API — building forms with FormBase/ConfigFormBase, form elements, validate/submit handlers, DI, and generating forms with Drush including routes.
In this repository35 other files it gives its agents.
- ddev-expertSkill
- docker-localSkill
- drupal-accessSkill
- drupal-cachingSkill
- drupal-composerSkill
- drupal-configSkill
- drupal-contrib-mgmtSkill
- drupal-debuggingSkill
- drupal-drushSkill
- drupal-dttSkill
- drupal-entity-apiSkill
- drupal-eventsSkill
- drupal-fieldsSkill
- drupal-form-ajaxSkill
- drupal-form-alterSkill
- drupal-form-validationSkill
- drupal-hooksSkill
- drupal-htmxSkill
- drupal-javascriptSkill
- drupal-kernelSkill
- drupal-menusSkill
- drupal-migrationsSkill
- drupal-paragraphsSkill
- drupal-pluginsSkill
- drupal-queriesSkill
- drupal-renderSkill
- drupal-routesSkill
- drupal-search-apiSkill
- drupal-securitySkill
- drupal-servicesSkill
- drupal-stateSkill
- drupal-taxonomySkill
- drupal-twigSkill
- drupal-unitSkill
- SKILL.mdSkill
The file
Files
Drupal Form API
Simple Form (FormBase)
// src/Form/MyForm.php
namespace Drupal\my_module\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
final class MyForm extends FormBase {
public function __construct(
private readonly EntityTypeManagerInterface $entityTypeManager,
) {}
public static function create(ContainerInterface $container): static {
return new static(
$container->get('entity_type.manager'),
);
}
public function getFormId(): string {
return 'my_module_my_form';
}
public function buildForm(array $form, FormStateInterface $form_state): array {
$form['name'] = [
'#type' => 'textfield',
'#title' => $this->t('Name'),
'#required' => TRUE,
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Submit'),
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state): void {
$name = $form_state->getValue('name');
$this->messenger()->addStatus($this->t('Hello @name!', ['@name' => $name]));
}
}Config Form (ConfigFormBase)
final class MySettingsForm extends ConfigFormBase {
protected function getEditableConfigNames(): array {
return ['my_module.settings'];
}
public function getFormId(): string {
return 'my_module_settings';
}
public function buildForm(array $form, FormStateInterface $form_state): array {
$config = $this->config('my_module.settings');
$form['enabled'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable feature'),
'#default_value' => $config->get('enabled'),
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state): void {
$this->config('my_module.settings')
->set('enabled', $form_state->getValue('enabled'))
->save();
parent::submitForm($form, $form_state);
}
}Common Form Elements
| Type | Description |
textfield | Single line text |
textarea | Multi-line text |
select | Dropdown |
checkboxes | Multiple checkboxes |
radios | Radio buttons |
checkbox | Single checkbox |
number | Numeric input |
email | Email input |
managed_file | Managed file upload |
entity_autocomplete | Entity reference autocomplete |
date | Date picker |
details | Collapsible group |
container | Non-visual wrapper |
hidden | Hidden field |
submit | Submit button |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

