How to Use AI in Drupal for Developers
As you probably already know in the Drupal world, reading and modifying dozens of files can become a tedious task. From experience I can tell you that integrating AI into your workflow doesn’t detract value: it helps you focus on what matters and speeds up repetitive phases. Here is my take on how to leverage AI tools, ensure your projects’ privacy, and—above all—generate and edit code faster and cleaner.
Why Use AI in Your Drupal Workflow?
Time Saving and Understanding Legacy Code
When you join a project with dozens of controllers, services, or Twig templates, AI allows you to “converse” with the code. You simply paste a snippet and ask “what does this do?” or “where might the performance bottleneck be?”. In seconds you have a summary—and best of all, you can apply mass refactorings: imagine updating ten services at once following a new template, instead of going file by file.
Cleaning and Standardizing Your Code
Beyond restructuring, AI injects comments in English following Drupal best practices, renames variables in Spanish to standard nomenclature (for example, changing $usuario_id
to $userId
), and generates docblocks before each function. The result is uniform, easy-to-read code for any team member, without losing your personal style.
AI Options and Privacy Considerations
In my tests, the options that have offered me the highest code quality are Anthropic’s Claude and Google’s Gemini. OpenAI also works, but I find its responses somewhat less precise for Drupal.
Keep in mind that any code you send to these services—including API keys in YAML config files, sensitive settings, or client data—will be used to retrain their models, which poses a privacy risk. Therefore, if you’re going to test external APIs, do so carefully and never send confidential information without first removing any sensitive data.
Ensuring Privacy with Local Solutions
Deploying Your Own AI Server
If your agency works with client data that cannot leave your infrastructure, the best option is to host the model on your own server or local machine. With containers (e.g., Docker) you can expose an internal API and ensure that no code snippet is sent outside your network. This way you comply with GDPR without complications: your data, your rules.
In the future I’ll talk more about this topic as I’m running tests and setting up a service that I’ll likely provide access to other agencies, so they can work with locally hosted AIs specially trained on Drupal code. Contact me if you’re interested in access for your agency.
Practical Use Cases
- Mass Refactoring of Simple Code
Apply a template to dozens of files (modules, services, controllers) at once. - Assistance with Complex Code
Paste logic blocks and ask for hints on potential bottlenecks or caching issues. - Code Translation and Cleanup
Convert comments or string literals from Spanish to English, rename variables and functions to follow Drupal community standards. - Bottleneck Detection
Index files or snippets and ask “which lines could slow down Drupal?”. AI points out common patterns and suggests where to investigate. - YAML Migration Templates
Using a base template for the Migrate module, generate migration files (nodes, taxonomies) from Drupal 7 to 10 with field mapping. Saves about 80% of the work, then a human just needs to verify that the migrations correctly transfer the field data.
IDEs and Extensions to Integrate It into Your Daily Routine
You only need to install the plugin from your IDE’s marketplace, configure your API key (or your local server’s URL), and keep working as usual.
You can use extensions for Visual Studio Code or PhpStorm if your team is already accustomed to them. But the option I recommend is using IDEs already geared toward working with AI—such as Cursor, WindSurf, or ZED. My current favorite is ZED. Note that Cursor doesn’t make it easy to work with local AIs while keeping your code’s privacy intact.
Conclusion
Integrating AI into Drupal isn’t magic—it’s a way to delegate the repetitive, understand legacy code in minutes, and keep your project clean. Whether you choose external services like Claude or Gemini, or prefer to deploy your own local solution for maximum privacy, you’ll gain speed and quality.
Have Any Project in Mind?
If you want to do something in Drupal maybe you can hire me.
Either for consulting, development or maintenance of Drupal websites.